1
- /*
1
+ /*
2
2
* @Author: sxf
3
3
* @Date: 2015-12-15 10:46:34
4
4
* @Last Modified by: sxf
@@ -61,7 +61,7 @@ const estring& estring::operator= (const std::string& str) {
61
61
const estring& estring::operator = (const char * cstr) {
62
62
autoreadstr (cstr);
63
63
return *this ;
64
- }
64
+ }
65
65
66
66
const estring& estring::operator = (const echar_t * ecstr) {
67
67
this ->data = ecstr;
@@ -96,10 +96,10 @@ void estring::readstr (const std::string& str, const std::string& encode) {
96
96
void estring::readstr (const char * data, const std::string& encode) {
97
97
assert (data != NULL );
98
98
iconv_t cd = iconv_open (" UTF-16LE" , encode.c_str ()); // tocode, fromcode
99
- if ((iconv_t )-1 == cd) {
99
+ if ((iconv_t )-1 == cd) {
100
100
printf (" 不能从编码 %s 转换到 %s!\n " , encode.c_str (), " UTF-16LE" );
101
- return ;
102
- }
101
+ return ;
102
+ }
103
103
size_t in_size = strlen (data);
104
104
size_t out_size = BUFFER_SIZE;
105
105
size_t malloc_size = out_size;
@@ -121,7 +121,7 @@ void estring::readstr (const char* data, const std::string& encode) {
121
121
} else {
122
122
printf (" %s\n " , strerror (errno));
123
123
free (outbuf);
124
- return ;
124
+ return ;
125
125
}
126
126
}
127
127
}
@@ -149,10 +149,10 @@ std::string estring::to_utf8() {
149
149
150
150
std::string estring::to_str (const std::string& encode) {
151
151
iconv_t cd = iconv_open (encode.c_str (), " UTF-16LE" ); // tocode, fromcode
152
- if ((iconv_t )-1 == cd) {
152
+ if ((iconv_t )-1 == cd) {
153
153
printf (" 不能从编码 %s 转换到 %s!\n " , encode.c_str (), " UTF-16LE" );
154
- return " " ;
155
- }
154
+ return " " ;
155
+ }
156
156
std::string _ToStr;
157
157
char * data = (char *)(this ->data .data ());
158
158
size_t in_size = this ->data .size () * 2 ;
@@ -175,7 +175,7 @@ std::string estring::to_str(const std::string& encode) {
175
175
} else {
176
176
printf (" %s\n " , strerror (errno));
177
177
free (outbuf);
178
- return _ToStr = " " ;
178
+ return _ToStr = " " ;
179
179
}
180
180
}
181
181
}
@@ -190,10 +190,8 @@ std::string estring::to_str(const std::string& encode) {
190
190
191
191
192
192
int estring::find (echar_t c) const {
193
- int i = 0 ;
194
- for (auto p : data) {
195
- if (p == c) return i;
196
- ++i;
193
+ for (const_iterator p = data.begin (); p != data.end (); ++p) {
194
+ if (*p == c) return p - data.begin ();
197
195
}
198
196
return -1 ;
199
197
}
@@ -230,17 +228,17 @@ estring::encodedetect (const char* data) {
230
228
231
229
int size = strlen (data);
232
230
int result = csd_consider (csd, data, size);
233
- if (result < 0 )
231
+ if (result < 0 )
234
232
return NULL ;
235
233
return csd_close (csd);
236
234
}
237
235
238
- std::string
236
+ std::string
239
237
estring::load_full_file (const std::string& path) {
240
- std::ifstream t (path);
238
+ std::ifstream t (path. c_str () );
241
239
std::string str;
242
240
243
- t.seekg (0 , std::ios::end);
241
+ t.seekg (0 , std::ios::end);
244
242
str.reserve (t.tellg ());
245
243
t.seekg (0 , std::ios::beg);
246
244
@@ -259,4 +257,4 @@ estring::iterator estring::end() {
259
257
260
258
void estring::push_back (echar_t c) {
261
259
data.push_back (c);
262
- }
260
+ }
0 commit comments