Skip to content

Commit ebf3304

Browse files
committed
down to C++98
1 parent 3770b81 commit ebf3304

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
2020
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
2121
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
2222

23-
set( CMAKE_CXX_STANDARD 11)
23+
set( CMAKE_CXX_STANDARD 98)
2424

2525
file(GLOB_RECURSE source_files
2626
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp

include/estring.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef ESTRING_H
88
#define ESTRING_H
99

10-
#include <cstdint>
10+
#include <stdint.h>
1111
#include <cstddef>
1212
#include <string>
1313
#include <vector>
@@ -22,7 +22,8 @@ class estring
2222
{
2323
public:
2424
typedef std::basic_string<echar_t>::iterator iterator;
25-
25+
typedef std::basic_string<echar_t>::const_iterator const_iterator;
26+
2627
estring();
2728
estring(const std::string& str);
2829
estring(const estring& estr);

src/estring.cpp

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* @Author: sxf
33
* @Date: 2015-12-15 10:46:34
44
* @Last Modified by: sxf
@@ -61,7 +61,7 @@ const estring& estring::operator= (const std::string& str) {
6161
const estring& estring::operator= (const char* cstr) {
6262
autoreadstr(cstr);
6363
return *this;
64-
}
64+
}
6565

6666
const estring& estring::operator= (const echar_t* ecstr) {
6767
this->data = ecstr;
@@ -96,10 +96,10 @@ void estring::readstr (const std::string& str, const std::string& encode) {
9696
void estring::readstr (const char* data, const std::string& encode) {
9797
assert (data != NULL);
9898
iconv_t cd = iconv_open ("UTF-16LE", encode.c_str()); // tocode, fromcode
99-
if ((iconv_t)-1 == cd) {
99+
if ((iconv_t)-1 == cd) {
100100
printf("不能从编码 %s 转换到 %s!\n", encode.c_str(), "UTF-16LE");
101-
return;
102-
}
101+
return;
102+
}
103103
size_t in_size = strlen(data);
104104
size_t out_size = BUFFER_SIZE;
105105
size_t malloc_size = out_size;
@@ -121,7 +121,7 @@ void estring::readstr (const char* data, const std::string& encode) {
121121
} else {
122122
printf ("%s\n", strerror(errno));
123123
free (outbuf);
124-
return;
124+
return;
125125
}
126126
}
127127
}
@@ -149,10 +149,10 @@ std::string estring::to_utf8() {
149149

150150
std::string estring::to_str(const std::string& encode) {
151151
iconv_t cd = iconv_open (encode.c_str(), "UTF-16LE"); // tocode, fromcode
152-
if ((iconv_t)-1 == cd) {
152+
if ((iconv_t)-1 == cd) {
153153
printf("不能从编码 %s 转换到 %s!\n", encode.c_str(), "UTF-16LE");
154-
return "";
155-
}
154+
return "";
155+
}
156156
std::string _ToStr;
157157
char* data = (char*)(this->data.data());
158158
size_t in_size = this->data.size() * 2;
@@ -175,7 +175,7 @@ std::string estring::to_str(const std::string& encode) {
175175
} else {
176176
printf ("%s\n", strerror(errno));
177177
free (outbuf);
178-
return _ToStr = "";
178+
return _ToStr = "";
179179
}
180180
}
181181
}
@@ -190,10 +190,8 @@ std::string estring::to_str(const std::string& encode) {
190190

191191

192192
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();
197195
}
198196
return -1;
199197
}
@@ -230,17 +228,17 @@ estring::encodedetect (const char* data) {
230228

231229
int size = strlen(data);
232230
int result = csd_consider(csd, data, size);
233-
if (result < 0)
231+
if (result < 0)
234232
return NULL;
235233
return csd_close(csd);
236234
}
237235

238-
std::string
236+
std::string
239237
estring::load_full_file(const std::string& path) {
240-
std::ifstream t(path);
238+
std::ifstream t(path.c_str());
241239
std::string str;
242240

243-
t.seekg(0, std::ios::end);
241+
t.seekg(0, std::ios::end);
244242
str.reserve(t.tellg());
245243
t.seekg(0, std::ios::beg);
246244

@@ -259,4 +257,4 @@ estring::iterator estring::end() {
259257

260258
void estring::push_back(echar_t c) {
261259
data.push_back(c);
262-
}
260+
}

test_package/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ cmake_minimum_required(VERSION 2.8)
44
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
55
conan_basic_setup()
66

7-
set( CMAKE_CXX_STANDARD 11)
7+
set( CMAKE_CXX_STANDARD 98)
88
add_executable(test main.cpp)
99
target_link_libraries(test ${CONAN_LIBS})

0 commit comments

Comments
 (0)