Rename getline function to unsafe, to make it greppable.
Now i can trim them one-by-one.
This commit is contained in:
30
dlib/dlib.cc
30
dlib/dlib.cc
@ -942,7 +942,7 @@ char *dGethomedir (void)
|
||||
* Get a line from a FILE stream.
|
||||
* Return value: read line on success, NULL on EOF.
|
||||
*/
|
||||
char *dGetline (FILE *stream)
|
||||
char *dGetline_unsafe (FILE *stream)
|
||||
{
|
||||
int ch;
|
||||
Dstr *dstr;
|
||||
@ -963,24 +963,24 @@ char *dGetline (FILE *stream)
|
||||
}
|
||||
|
||||
std::optional< std::string >
|
||||
dGetline_string (FILE *stream)
|
||||
dGetline( FILE *const stream )
|
||||
{
|
||||
int ch;
|
||||
Dstr *dstr;
|
||||
std::string rv;
|
||||
int ch;
|
||||
|
||||
if( stream == nullptr ) return std::nullopt;
|
||||
if( stream == nullptr ) return std::nullopt;
|
||||
|
||||
dstr = dStr_sized_new(64);
|
||||
while ((ch = fgetc(stream)) != EOF) {
|
||||
dStr_append_c(dstr, ch);
|
||||
if (ch == '\n')
|
||||
break;
|
||||
}
|
||||
while( ( ch= fgetc( stream ) ) != EOF )
|
||||
{
|
||||
rv+= ch;
|
||||
if (ch == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
std::optional< std::string > line;
|
||||
if(dstr->len) line= dstr->str;
|
||||
dStr_free(dstr, 1);
|
||||
return line;
|
||||
std::optional< std::string > line;
|
||||
if(rv.size()) line= std::move( rv );
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,7 +186,8 @@ void dLib_show_messages(bool show);
|
||||
char *dGetcwd(void);
|
||||
char *dGethomedir(void);
|
||||
std::optional< std::string > dGetline_string(FILE *stream);
|
||||
char *dGetline(FILE *stream);
|
||||
char *dGetline_unsafe(FILE *stream);
|
||||
std::optional< std::string > dGetline(FILE *stream);
|
||||
int dClose(int fd);
|
||||
int dUsleep(unsigned long us);
|
||||
|
||||
|
Reference in New Issue
Block a user