sub_srt.cpp:
Код: Выделить всё
#include "sub.h"
#include "sub_srt.h"
#include <string>
#include <iostream>
using namespace std;
bool read_srt_header(/*__sub *sub*/){
string str;
string s_start, s_end;
cin >> str;
int sep_pos = str.find (srt_separator);
/*s_start = str.substr (0, sep_pos);
s_end = str.substr (sep_pos + srt_separator.length(), str.length() - sep_pos + srt_separator.length());*/
/*debugging code*/
cout << "str = " << str << "\n";
cout << "sep_pos =" << sep_pos << "\n sep_pos + srt_separator.length() = " << sep_pos + srt_separator.length() << "\n";
cout << "s_start = " << s_start << "\n" << "s_end = " << s_end << "\n";
}
int main () {
read_srt_header();
return(0);
}sub_srt.h:
Код: Выделить всё
#include <string>
using namespace std;
const string srt_separator ("-->");sub.h:
Код: Выделить всё
/* __sub type declarations */
/* (c) Minoru Horaki (Bazylik), 06.07.2007*/
#include <string>
using namespace std;
typedef struct __sub
{
int starttime; /*starttime in milliseconds*/
int time_val; /* show duration in milliseconds */
string type; /*type header*/
string style; /* style header*/
string text; /*text value*/
}__sub;Почему-то функция string::find работает корректно только в случае, если в главной строке нет пробелов. В итоге, получаем вот такую бяку:
Код: Выделить всё
minoru@minoru-desktop:~/projects/subsanity$ g++ sub_srt.cpp
minoru@minoru-desktop:~/projects/subsanity$ ./a.out
+++++-->++++
str = +++++-->++++
sep_pos =5
sep_pos + srt_separator.length() = 8
s_start =
s_end =
minoru@minoru-desktop:~/projects/subsanity$ ./a.out
-->
str = -->
sep_pos =0
sep_pos + srt_separator.length() = 3
s_start =
s_end =
minoru@minoru-desktop:~/projects/subsanity$ ./a.out
00:00:00 --> 00:00:00
str = 00:00:00
sep_pos =-1
sep_pos + srt_separator.length() = 2
s_start =
s_end =
minoru@minoru-desktop:~/projects/subsanity$ ./a.out
00:00:00-->00:00:00
str = 00:00:00-->00:00:00
sep_pos =8
sep_pos + srt_separator.length() = 11
s_start =
s_end =На данный момент это - единственный камень преткновения. Можно, конечно, добавить строчку, заменяющую все пробелы на "+", но это - весьма сомнительный стиль программирования, поэтому, меня никак не устраивает. Что делать?