30.11.2013 - New PICollection namespace, Android support, my own PIVector implementation
This commit is contained in:
49
pistring.cpp
49
pistring.cpp
@@ -85,7 +85,7 @@ void PIString::appendFromChars(const char * c, int s) {
|
||||
push_back(PIChar(c[i]));
|
||||
continue;
|
||||
}
|
||||
sz = mbtowc(&wc, &c[i], 4);
|
||||
sz = mbtowc(&wc, &(c[i]), 4);
|
||||
//cout << sz << endl;
|
||||
switch (sz) {
|
||||
case 4:
|
||||
@@ -378,7 +378,10 @@ PIString PIString::takeWord() {
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
PIChar c = at(i);
|
||||
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
|
||||
if (we < 0 && ws >= 0) we = i;
|
||||
if (we < 0 && ws >= 0) {
|
||||
we = i;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (ws < 0) ws = i;
|
||||
if (we >= 0) break;
|
||||
@@ -390,6 +393,37 @@ PIString PIString::takeWord() {
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::takeCWord() {
|
||||
PIString ret;
|
||||
int sz = size_s(), ws = -1, we = -1;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
PIChar c = at(i);
|
||||
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
|
||||
if (we < 0 && ws >= 0) {
|
||||
we = i;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (ws < 0) {
|
||||
if (c.isAlpha() || c == '_')
|
||||
ws = i;
|
||||
else
|
||||
return ret;
|
||||
} else {
|
||||
if (!c.isAlpha() && !c.isDigit() && c != '_') {
|
||||
we = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (we >= 0) break;
|
||||
}
|
||||
}
|
||||
ret = mid(ws, we - ws);
|
||||
cutLeft(we < 0 ? sz : we);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::takeLine() {
|
||||
int sz = size_s(), le = -1;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
@@ -528,13 +562,16 @@ int PIString::lengthAscii() const {
|
||||
|
||||
const char * PIString::data() const {
|
||||
data_.clear();
|
||||
int wc;
|
||||
uint wc;
|
||||
uchar tc;
|
||||
//printf("PIString::data %d\n", size_s());
|
||||
for (int i = 0, j = 0; i < size_s(); ++i) {
|
||||
wc = at(i).toInt();
|
||||
wc = uint(at(i).toInt());
|
||||
//printf("__%d_%d\n", i, wc);
|
||||
while (tc = wc & 0xFF, tc) {
|
||||
data_.push_back(uchar(tc)); ++j;
|
||||
wc >>= 8;
|
||||
//printf("____%d\n", wc);
|
||||
}
|
||||
/*if (at(i).isAscii())
|
||||
data_.push_back(uchar(at(i).toAscii()));
|
||||
@@ -550,11 +587,11 @@ const char * PIString::data() const {
|
||||
|
||||
string PIString::convertToStd() const {
|
||||
string s;
|
||||
int wc;
|
||||
uint wc;
|
||||
uchar tc;
|
||||
if (size() > 0) {
|
||||
for (int i = 0; i < length(); ++i) {
|
||||
wc = at(i).toInt();
|
||||
wc = uint(at(i).toInt());
|
||||
while (tc = wc & 0xFF, tc) {
|
||||
s.push_back(char(tc));
|
||||
wc >>= 8;
|
||||
|
||||
Reference in New Issue
Block a user