comparison base/StringBits.cpp @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents 48e9f538e6e9
children 21c792334c2e
comparison
equal deleted inserted replaced
1324:d4a28d1479a8 1527:710e6250a401
40 while (i < len && s[i].isSpace()) ++i; 40 while (i < len && s[i].isSpace()) ++i;
41 if (i < len && s[i] == '-') sign = -1; 41 if (i < len && s[i] == '-') sign = -1;
42 42
43 while (i < len) { 43 while (i < len) {
44 44
45 QChar c = s[i]; 45 QChar c = s[i];
46 46
47 if (c.isDigit()) { 47 if (c.isDigit()) {
48 48
49 double d = c.digitValue(); 49 double d = c.digitValue();
50 50
83 // q2 -> in a double-quoted field 83 // q2 -> in a double-quoted field
84 84
85 enum { sep, unq, q1, q2 } mode = sep; 85 enum { sep, unq, q1, q2 } mode = sep;
86 86
87 for (int i = 0; i < s.length(); ++i) { 87 for (int i = 0; i < s.length(); ++i) {
88 88
89 QChar c = s[i]; 89 QChar c = s[i];
90 90
91 if (c == '\'') { 91 if (c == '\'') {
92 switch (mode) { 92 switch (mode) {
93 case sep: mode = q1; break; 93 case sep: mode = q1; break;
94 case unq: case q2: tok += c; break; 94 case unq: case q2: tok += c; break;
95 case q1: mode = unq; break; 95 case q1: mode = unq; break;
96 } 96 }
97 97
98 } else if (c == '"') { 98 } else if (c == '"') {
99 switch (mode) { 99 switch (mode) {
100 case sep: mode = q2; break; 100 case sep: mode = q2; break;
101 case unq: case q1: tok += c; break; 101 case unq: case q1: tok += c; break;
102 case q2: mode = unq; break; 102 case q2: mode = unq; break;
103 } 103 }
104 104
105 } else if (c == separator || (separator == ' ' && c.isSpace())) { 105 } else if (c == separator || (separator == ' ' && c.isSpace())) {
106 switch (mode) { 106 switch (mode) {
107 case sep: if (separator != ' ') tokens << ""; break; 107 case sep: if (separator != ' ') tokens << ""; break;
108 case unq: mode = sep; tokens << tok; tok = ""; break; 108 case unq: mode = sep; tokens << tok; tok = ""; break;
109 case q1: case q2: tok += c; break; 109 case q1: case q2: tok += c; break;
110 } 110 }
111 111
112 } else if (c == '\\') { 112 } else if (c == '\\') {
113 if (++i < s.length()) { 113 if (++i < s.length()) {
114 c = s[i]; 114 c = s[i];
115 switch (mode) { 115 switch (mode) {
116 case sep: mode = unq; tok += c; break; 116 case sep: mode = unq; tok += c; break;
117 case unq: case q1: case q2: tok += c; break; 117 case unq: case q1: case q2: tok += c; break;
118 } 118 }
119 } 119 }
120 120
121 } else { 121 } else {
122 switch (mode) { 122 switch (mode) {
123 case sep: mode = unq; tok += c; break; 123 case sep: mode = unq; tok += c; break;
124 case unq: case q1: case q2: tok += c; break; 124 case unq: case q1: case q2: tok += c; break;
125 } 125 }
126 } 126 }
127 } 127 }
128 128
129 if (tok != "" || mode != sep) { 129 if (tok != "" || mode != sep) {
130 if (mode == q1) { 130 if (mode == q1) {
131 tokens << ("'" + tok); // turns out it wasn't quoted after all 131 tokens << ("'" + tok); // turns out it wasn't quoted after all