8000 exlib, refactor: refactor string. · fibjs/fibjs@539a916 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 539a916

Browse files
committed
exlib, refactor: refactor string.
1 parent bc4b8f1 commit 539a916

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+235
-250
lines changed

fibjs/include/ChildProcess.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ChildProcess : public ChildProcess_base {
6868
result_t create_pipe(int32_t idx);
6969
result_t fill_stdio(v8::Local<v8::Object> options, bool fork);
7070
result_t fill_env(v8::Local<v8::Object> options);
71-
result_t fill_arg(exlib::string command, v8::Local<v8::Array> args);
71+
result_t fill_arg(v8::Local<v8::Array> args);
7272
result_t fill_opt(v8::Local<v8::Object> options);
7373

7474
public:
@@ -95,6 +95,8 @@ class ChildProcess : public ChildProcess_base {
9595

9696
std::vector<char*> envp;
9797

98+
exlib::string m_command;
99+
98100
std::vector<exlib::string> argStr;
99101
std::vector<char*> _args;
100102

fibjs/include/Redis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class Redis : public Redis_base {
216216
sz = snprintf(numStr, sizeof(numStr), "*%d\r\n", (int32_t)m_params.size() / 2);
217217

218218
str.resize(sz + m_size);
219-
p = str.c_buffer();
219+
p = str.data();
220220

221221
memcpy(p, numStr, sz);
222222
p += sz;

fibjs/include/StringBuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class StringBuffer {
3131
s = m_array[0];
3232
else {
3333
s.resize(m_size);
34-
char* _s = s.c_buffer();
34+
char* _s = s.data();
3535

3636
for (i = 0; i < (int32_t)m_array.size(); i++) {
3737
exlib::string& s1 = m_array[i];

fibjs/include/StringDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ inline exlib::string normalizeEncoding(exlib::string encoding)
180180
} else {
181181
if (retried)
182182
return "$not valid$";
183-
encoding.tolower();
183+
exlib::qstrlwr(encoding);
184184
retried = true;
185185
}
186186
}

fibjs/include/UVStream.h

Lines changed: 1 addition & 1 deletion< 6851 div class="d-flex">
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class UVStream_tmpl : public T {
139139
ar->m_buf.resize(suggested_size);
140140
}
141141

142-
buf->base = ar->m_buf.c_buffer() + ar->m_pos;
142+
buf->base = ar->m_buf.data() + ar->m_pos;
143143
buf->len = (int32_t)(ar->m_buf.length() - ar->m_pos);
144144
}
145145

fibjs/include/Url.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Url : public UrlObject_base {
122122
}
123123

124124
str.resize(len);
125-
bstr = str.c_buffer();
125+
bstr = str.data();
126126

127127
for (len = 0, src = url, l = sz; l > 0; src++, len++, l--) {
128128
ch = (unsigned char)*src;
@@ -181,7 +181,7 @@ class Url : public UrlObject_base {
181181
}
182182

183183
str.resize(len);
184-
bstr = str.c_buffer();
184+
bstr = str.data();
185185

186186
for (src = url, l = sz; l > 0; l--) {
187187
ch = (unsigned char)*src++;

fibjs/include/XmlDataImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class XmlDataImpl {
156156
return m_data;
157157

158158
str.resize(sz1);
159-
char* data1 = str.c_buffer();
159+
char* data1 = str.data();
160160

161161
for (i = 0; i < sz; i++) {
162162
char ch;

fibjs/include/XmlElement.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class XmlElement : public XmlElement_base, public XmlNodeImpl {
2626
, m_attrs(new XmlNamedNodeMap())
2727
{
2828
if (!m_isXml)
29-
qstrupr(m_tagName.c_buffer());
29+
exlib::qstrupr(m_tagName);
3030
}
3131

3232
XmlElement(XmlDocument_base* document, exlib::string namespaceURI, exlib::string qualifiedName, bool isXml)
@@ -46,7 +46,7 @@ class XmlElement : public XmlElement_base, public XmlNodeImpl {
4646
}
4747

4848
if (!m_isXml)
49-
qstrupr(m_tagName.c_buffer());
49+
exlib::qstrupr(m_tagName);
5050
}
5151

5252
XmlElement(const XmlElement& from)

fibjs/include/path.h

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Path {
5454
diskId = c_str[0];
5555
m_buf = m_disks[diskId & 0x1f];
5656
if (m_buf.length())
57-
m_buf.c_buffer()[0] = c_str[0];
57+
m_buf.data()[0] = c_str[0];
5858
c_str += 2;
5959
}
6060

@@ -74,7 +74,7 @@ class Path {
7474
if (is_root || base.empty())
7575
base = c_str;
7676
else {
77-
if (!isWin32PathSlash(base[base.length() - 1]))
77+
if (!isWin32PathSlash(base.c_str()[base.length() - 1]))
7878
base.append(1, PATH_SLASH_WIN32);
7979

8080
base.append(c_str);
@@ -100,7 +100,7 @@ class Path {
100100
if (isPosixPathSlash(c_str[0]) || m_buf.empty())
101101
m_buf = other;
102102
else {
103-
if (!isPosixPathSlash(m_buf[m_buf.length() - 1]))
103+
if (!isPosixPathSlash(m_buf.c_str()[m_buf.length() - 1]))
104104
m_buf.append(1, PATH_SLASH_POSIX);
105105

106106
m_buf.append(other);
@@ -113,13 +113,13 @@ class Path {
113113
return;
114114

115115
if (m_buf.length() == 0 && other.length() == 2
116-
&& isWin32PathSlash(other[0]) && isWin32PathSlash(other[1])) {
116+
&& isWin32PathSlash(other.c_str()[0]) && isWin32PathSlash(other.c_str()[1])) {
117117
m_buf.append(1, PATH_SLASH_WIN32);
118118
return;
119-
} else if (m_buf.length() == 1 && isWin32PathSlash(m_buf[0])) {
120-
if (isWin32PathSlash(other[0]))
119+
} else if (m_buf.length() == 1 && isWin32PathSlash(m_buf.c_str()[0])) {
120+
if (isWin32PathSlash(other.c_str()[0]))
121121
m_buf.clear();
122-
} else if (m_buf.length() > 0 && !isWin32PathSlash(m_buf[m_buf.length() - 1]))
122+
} else if (m_buf.length() > 0 && !isWin32PathSlash(m_buf.c_str()[m_buf.length() - 1]))
123123
m_buf.append(1, PATH_SLASH_WIN32);
124124

125125
m_buf.append(other);
@@ -130,7 +130,7 @@ class Path {
130130
if (other.empty())
131131
return;
132132

133-
if (m_buf.length() > 0 && !isPosixPathSlash(m_buf[m_buf.length() - 1]))
133+
if (m_buf.length() > 0 && !isPosixPathSlash(m_buf.c_str()[m_buf.length() - 1]))
134134
m_buf.append(1, PATH_SLASH_POSIX);
135135

136136
m_buf.append(other);
@@ -566,7 +566,7 @@ inline result_t _parse(exlib::string path, obj_ptr<NObject>& retVal)
566566
return 0;
567567
}
568568

569-
bool isAbsolute = path[0] == CHAR_FORWARD_SLASH;
569+
bool isAbsolute = path.c_str()[0] == CHAR_FORWARD_SLASH;
570570
int start;
571571
if (isAbsolute) {
572572
ret->add("root", "/");
@@ -582,7 +582,7 @@ inline result_t _parse(exlib::string path, obj_ptr<NObject>& retVal)
582582
int preDotState = 0;
583583

584584
for (; i >= start; --i) {
585-
int code = path[i];
585+
int code = path.c_str()[i];
586586
if (code == CHAR_FORWARD_SLASH) {
587587
if (!matchedSlash) {
588588
startPart = i + 1;
@@ -637,7 +637,7 @@ inline result_t _parse_win32(exlib::string path, obj_ptr<NObject>& retVal)
637637

638638
int len = (int)path.length();
639639
int rootEnd = 0;
640-
int code = path[0];
640+
int code = path.c_str()[0];
641641

642642
if (len == 1) {
643643
if (isPathSeparator(code)) {
@@ -653,18 +653,18 @@ inline result_t _parse_win32(exlib::string path, obj_ptr<NObject>& retVal)
653653
}
654654
if (isPathSeparator(code)) {
655655
rootEnd = 1;
656-
if (isPathSeparator(path[1])) {
656+
if (isPathSeparator(path.c_str()[1])) {
657657
int j = 2;
658658
int last = j;
659-
while (j < len && !isPathSeparator(path[j]))
659+
while (j < len && !isPathSeparator(path.c_str()[j]))
660660
j++;
661661
if (j < len && j != last) {
662662
last = j;
663-
while (j < len && isPathSeparator(path[j]))
663+
while (j < len && isPathSeparator(path.c_str()[j]))
664664
j++;
665665
if (j < len && j != last) {
666666
last = j;
667-
while (j < len && !isPathSeparator(path[j]))
667+
while (j < len && !isPathSeparator(path.c_str()[j]))
668668
j++;
669669
if (j == len)
670670
rootEnd = j;
@@ -673,7 +673,7 @@ inline result_t _parse_win32(exlib::string path, obj_ptr<NObject>& retVal)
673673
}
674674
}
675675
}
676-
} else if (isWindowsDeviceRoot(code) && path[1] == CHAR_COLON) {
676+
} else if (isWindowsDeviceRoot(code) && path.c_str()[1] == CHAR_COLON) {
677677
if (len <= 2) {
678678
ret->add("root", path);
679679
ret->add("dir", path);
@@ -682,7 +682,7 @@ inline result_t _parse_win32(exlib::string path, obj_ptr<NObject>& retVal)
682682
return 0;
683683
}
684684
rootEnd = 2;
685-
if (isPathSeparator(path[2])) {
685+
if (isPathSeparator(path.c_str()[2])) {
686686
if (len == 3) {
687687
ret->add("root", path);
688688
ret->add("dir", path);
@@ -705,7 +705,7 @@ inline result_t _parse_win32(exlib::string path, obj_ptr<NObject>& retVal)
705705
int preDotState = 0;
706706

707707
for (; i >= rootEnd; --i) {
708-
code = path[i];
708+
code = path.c_str()[i];
709709
if (isPathSeparator(code)) {
710710
if (!matchedSlash) {
711711
startPart = i + 1;
@@ -902,7 +902,7 @@ inline result_t _relative(exlib::string from, exlib::string to, exlib::string& r
902902
// Trim any leading backslashes
903903
int32_t fromStart = 1;
904904
for (; fromStart < (int32_t)from.length(); ++fromStart) {
905-
if (!isPosixPathSlash(from[fromStart]))
905+
if (!isPosixPathSlash(from.c_str()[fromStart]))
906906
break;
907907
}
908908
int32_t fromEnd = (int32_t)from.length();
@@ -911,7 +911,7 @@ inline result_t _relative(exlib::string from, exlib::string to, exlib::string& r
911911
// Trim any leading backslashes
912912
int32_t toStart = 1;
913913
for (; toStart < (int32_t)to.length(); ++toStart) {
914-
if (!isPosixPathSlash(to[toStart]))
914+
if (!isPosixPathSlash(to.c_str()[toStart]))
915915
break;
916916
}
917917
int32_t toEnd = (int32_t)to.length();
@@ -924,7 +924,7 @@ inline result_t _relative(exlib::string from, exlib::string to, exlib::string& r
924924
for (; i <= length; ++i) {
925925
if (i == length) {
926926
if (toLen > length) {
927-
if (isPosixPathSlash(to[toStart + i])) {
927+
if (isPosixPathSlash(to.c_str()[toStart + i])) {
928928
// We get here if `from` is the exact base path for `to`.
929929
// For example: from='/foo/bar'; to='/foo/bar/baz'
930930
return _normalize(to.substr(toStart + i + 1), retVal, false);
@@ -935,7 +935,7 @@ inline result_t _relative(exlib::string from, exlib::string to, exlib::string& r
935935
}
936936

937937
} else if (fromLen > length) {
938-
if (isPosixPathSlash(from[fromStart + i])) {
938+
if (isPosixPathSlash(from.c_str()[fromStart + i])) {
939939
// We get here if `to` is the exact base path for `from`.
940940
// For example: from='/foo/bar/baz'; to='/foo/bar'
941941
lastCommonSep = i;
@@ -947,8 +947,8 @@ inline result_t _relative(exlib::string from, exlib::string to, exlib::string& r
947947
}
948948
break;
949949
}
950-
char fromChar = from[fromStart + i];
951-
char toChar = to[toStart + i];
950+
char fromChar = from.c_str()[fromStart + i];
951+
char toChar = to.c_str()[toStart + i];
952952
if (fromChar != toChar)
953953
break;
954954
else if (isPosixPathSlash(fromChar))
@@ -959,7 +959,7 @@ inline result_t _relative(exlib::string from, exlib::string to, exlib::string& r
959959
// Generate the relative path based on the path difference between `to`
960960
// and `from`
961961
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
962-
if (i == fromEnd || isPosixPathSlash(from[i])) {
962+
if (i == fromEnd || isPosixPathSlash(from.c_str()[i])) {
963963
if (out.length() == 0)
964964
out += "..";
965965
else
@@ -973,7 +973,7 @@ inline result_t _relative(exlib::string from, exlib::string to, exlib::string& r
973973
return _normalize(out + to.substr(toStart + lastCommonSep), retVal, false);
974974
} else {
975975
toStart += lastCommonSep;
976-
if (isPosixPathSlash(to[toStart]))
976+
if (isPosixPathSlash(to.c_str()[toStart]))
977977
++toStart;
978978

979979
return _normalize(to.substr(toStart), retVal, false);
@@ -1004,37 +1004,37 @@ inline result_t _relative_win32(exlib::string from, exlib::string to, exlib::str
10041004
return 0;
10051005

10061006
from = "" + fromOrig;
1007-
from.tolower();
1007+
exlib::qstrlwr(from);
10081008
to = "" + toOrig;
1009-
to.tolower();
1009+
exlib::qstrlwr(to);
10101010

10111011
if (from == to)
10121012
return 0;
10131013

10141014
// Trim any leading backslashes
10151015
int32_t fromStart = 0;
10161016
for (; fromStart < (int32_t)from.length(); ++fromStart) {
1017-
if (!isWin32PathSlash(from[fromStart]))
1017+
if (!isWin32PathSlash(from.c_str()[fromStart]))
10181018
break;
10191019
}
10201020
// Trim trailing backslashes (applicable to UNC paths only)
10211021
int32_t fromEnd = (int32_t)from.length();
10221022
for (; fromEnd - 1 > fromStart; --fromEnd) {
1023-
if (!isWin32PathSlash(from[fromEnd - 1]))
1023+
if (!isWin32PathSlash(from.c_str()[fromEnd - 1]))
10241024
break;
10251025
}
10261026
int32_t fromLen = (fromEnd - fromStart);
10271027

10281028
// Trim any leading backslashes
10291029
int32_t toStart = 0;
10301030
for (; toStart < (int32_t)to.length(); ++toStart) {
1031-
if (!isWin32PathSlash(to[toStart]))
1031+
if (!isWin32PathSlash(to.c_str()[toStart]))
10321032
break;
10331033
}
10341034
// Trim trailing backslashes (applicable to UNC paths only)
10351035
int32_t toEnd = (int32_t)to.length();
10361036
for (; toEnd - 1 > toStart; --toEnd) {
1037-
if (!isWin32PathSlash(to[toEnd - 1]))
1037+
if (!isWin32PathSlash(to.c_str()[toEnd - 1]))
10381038
break;
10391039
}
10401040
int32_t toLen = (toEnd - toStart);
@@ -1046,7 +1046,7 @@ inline result_t _relative_win32(exlib::string from, exlib::string to, exlib::str
10461046
for (; i <= length; ++i) {
10471047
if (i == length) {
10481048
if (toLen > length) {
1049-
if (isWin32PathSlash(to[toStart + i])) {
1049+
if (isWin32PathSlash(to.c_str()[toStart + i])) {
10501050
// We get here if `from` is the exact base path for `to`.
10511051
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
10521052
return _normalize_win32(toOrig.substr(toStart + i + 1), retVal, true);
@@ -1057,7 +1057,7 @@ inline result_t _relative_win32(exlib::string from, exlib::string to, exlib::str
10571057
}
10581058
}
10591059
if (fromLen > length) {
1060-
if (isWin32PathSlash(from[fromStart + i])) {
1060+
if (isWin32PathSlash(from.c_str()[fromStart + i])) {
10611061
// We get here if `to` is the exact base path for `from`.
10621062
// For example: from='C:\\foo\\bar'; to='C:\\foo'
10631063
lastCommonSep = i;
@@ -1069,8 +1069,8 @@ inline result_t _relative_win32(exlib::string from, exlib::string to, exlib::str
10691069
}
10701070
break;
10711071
}
1072-
char fromChar = from[fromStart + i];
1073-
char toChar = to[toStart + i];
1072+
char fromChar = from.c_str()[fromStart + i];
1073+
char toChar = to.c_str()[toStart + i];
10741074
if (fromChar != toChar)
10751075
break;
10761076
else if (isWin32PathSlash(fromChar))
@@ -1089,7 +1089,7 @@ inline result_t _relative_win32(exlib::string from, exlib::string to, exlib::str
10891089
// Generate the relative path based on the path difference between `to` and
10901090
// `from`
10911091
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1092-
if (i == fromEnd || isWin32PathSlash(from[i])) {
1092+
if (i == fromEnd || isWin32PathSlash(from.c_str()[i])) {
10931093
if (out.length() == 0)
10941094
out += "..";
10951095
else
@@ -1103,7 +1103,7 @@ inline result_t _relative_win32(exlib::string from, exlib::string to, exlib::str
11031103
return _normalize_win32(out + toOrig.substr(toStart + lastCommonSep), retVal, true);
11041104
} else {
11051105
toStart += lastCommonSep;
1106-
if (isWin32PathSlash(toOrig[toStart]))
1106+
if (isWin32PathSlash(toOrig.c_str()[toStart]))
11071107
++toStart;
11081108
return _normalize_win32(toOrig.substr(toStart), retVal, true);
11091109
}
@@ -1123,7 +1123,7 @@ inline result_t _delimiter(exlib::string& retVal)
11231123

11241124
inline result_t _fullpath(exlib::string path, exlib::string& retVal)
11251125
{
1126-
if (isPathSlash(path[0]))
1126+
if (isPathSlash(path.c_str()[0]))
11271127
return _normalize(path, retVal);
11281128

11291129
exlib::string str;

0 commit comments

Comments
 (0)
0