4 #ifndef tools_buf2lines
5 #define tools_buf2lines
12 inline void buf2lines(
char* a_buffer,std::vector<std::string>& a_lines) {
19 if((*pos==
'\r')&&(*(pos+1)==
'\n')) {
21 a_lines.push_back(beg);
24 }
else if(*pos==
'\n') {
26 a_lines.push_back(beg);
30 a_lines.push_back(beg);
38 inline void buf2lines(
size_t a_size,
const char* a_buffer,std::vector<std::string>& a_lines) {
42 char* pos = (
char*)a_buffer;
43 const char*
end = a_buffer+a_size-1;
46 if(
line.size()) a_lines.push_back(
line);
49 if((*pos==
'\r')&&((pos+1)<=
end)&&(*(pos+1)==
'\n')) {
50 a_lines.push_back(
line);
53 }
else if(*pos==
'\n') {
54 a_lines.push_back(
line);
94 inline bool strings2buf(
const std::vector<std::string>& a_strings,
size_t& a_size,
char*& a_buffer) {
98 size_t number = a_strings.size();
100 for(
size_t index=0;index<number;index++) a_size += a_strings[index].
size()+1;
102 a_buffer =
new char[a_size];
103 if(!a_buffer) {a_size = 0;
return false;}
104 char* pos = a_buffer;
106 for(
size_t index=0;index<number;index++) {
107 const std::string& s = a_strings[index];
108 array_size = s.size()+1;
109 ::memcpy(pos,s.c_str(),array_size);
116 inline bool buf2strings(
size_t a_size,
char* a_buffer,std::vector<std::string>& a_strings) {
117 if(a_size<=1)
return false;
121 char*
begin = a_buffer;
122 char* pos = a_buffer;
123 size_t number = a_size-1;
124 for(
size_t index=0;index<number;index++) {
126 size_t l = pos -
begin;
128 char* data = (
char*)s.c_str();
129 ::memcpy(data,
begin,l);
130 a_strings.push_back(s);