Lolly 1.4.27
Loading...
Searching...
No Matches
Functions | Variables
analyze.cpp File Reference
#include "analyze.hpp"
#include "lolly/data/numeral.hpp"
#include "ntuple.hpp"
Include dependency graph for analyze.cpp:

Go to the source code of this file.

Functions

bool is_iso_alpha (char c)
 Checks if a character is an ISO alphabetic character.
 
bool is_iso_locase (char c)
 Checks if a character is an ISO lowercase alphabetic character.
 
bool is_iso_upcase (char c)
 Checks if a character is an ISO uppercase alphabetic character.
 
bool is_alpha (string s)
 Checks if a string contains only alphabetic characters.
 
bool is_alphanum (string s)
 
bool is_locase_alpha (string s)
 Checks if a string contains only lowercase alphabetic characters.
 
bool is_iso_alpha (string s)
 Checks if a string contains only ISO alphabetic characters.
 
bool is_numeric (string s)
 Checks if a string contains only numeric characters.
 
char upcase (char c)
 Converts a lowercase character to uppercase.
 
char locase (char c)
 Converts an uppercase character to lowercase.
 
char closing_delimiter (char c)
 Finds the closing delimiter corresponding to the given opening delimiter.
 
string upcase_first (string s)
 Converts the first character of a string to uppercase.
 
string locase_first (string s)
 Converts the first character of a string to lowercase.
 
string upcase_all (string s)
 Converts all lowercase characters in a string to uppercase.
 
string locase_all (string s)
 Converts all uppercase characters in a string to lowercase.
 
string string_union (string s1, string s2)
 Union of two strings.
 
string string_minus (string s1, string s2)
 Remove characters from one string that are in another string.
 
string remove_prefix (string s, string prefix)
 Remove the prefix from s if matches.
 
string remove_suffix (string s, string suffix)
 Remove the suffix from s if matches.
 
string ispanish_to_spanish (string s)
 Convert ispanish string to Spanish string.
 
string spanish_to_ispanish (string s)
 Convert Spanish string to ispanish string.
 
string igerman_to_german (string s)
 Convert igerman string to german string.
 
string german_to_igerman (string s)
 Convert german string to igerman string.
 
static char il2_to_cork (char c)
 
static char cork_to_il2 (char c)
 
string il2_to_cork (string s)
 
string cork_to_il2 (string s)
 
string alpha_nr (int nr)
 Generates an alphabetic string for an integer.
 
string Alpha_nr (int nr)
 Generates an uppercase alphabetic string for an integer.
 
string fnsymbol_nr (int nr)
 Generates footnote symbols for a given integer.
 
string raw_quote (string s)
 Add quotes around a string to indicate it's a string, not a symbol.
 
string raw_unquote (string s)
 Remove quotes from a string label.
 
string escape_sh (string s)
 Escape a string for use in shell scripts.
 
string escape_generic (string s)
 Escape a string with generic escape sequences.
 
string escape_verbatim (string s)
 Escape a string to be displayed verbatim.
 
string escape_spaces (string s)
 Escape spaces in a string with a backslash.
 
string dos_to_better (string s)
 Convert DOS line endings to more standard line endings.
 
string unescape_guile (string s)
 Unescape a Guile-syntax string.
 
bool test (string s, int i, const char *test)
 
bool test (string s, int i, string test)
 
bool starts (string s, const char *what)
 
bool starts (string s, const string what)
 
bool ends (string s, const char *what)
 
bool ends (string s, const string r)
 
bool read (string s, int &i, const char *test)
 
bool read (string s, string test)
 
bool read (string s, int &i, string test)
 
bool read_line (string s, int &i, string &result)
 
bool read_int (string s, int &i, int &result)
 
bool read_double (string s, int &i, double &result)
 
bool read_word (string s, int &i, string &result)
 
bool is_whitespace (string s)
 
void skip_spaces (string s, int &i)
 
void skip_whitespace (string s, int &i)
 
void skip_line (string s, int &i)
 
void skip_symbol (string s, int &i)
 
string convert_tabs_to_spaces (string s, int tw)
 Converts tabs in a string to spaces.
 
void parse (string s, int &pos, QI &ret)
 
void parse (string s, int &pos, QN &ret)
 
void parse (string s, int &pos, HI &ret)
 
void parse (string s, int &pos, HN &ret)
 
void parse (string s, int &pos, SI &ret)
 
void parse (string s, int &pos, SI *&a, int len)
 
int index_of (string s, char c)
 
int search_forwards (array< string > a, int pos, string in)
 
int search_forwards (string s, int pos, string in)
 
int search_forwards (string s, string in)
 
bool occurs (string what, string in)
 
bool contains (string s, string what)
 
bool contains (string s, char c)
 
int search_backwards (string s, int pos, string in)
 
int search_backwards (string s, string in)
 
int count_occurrences (string s, string in)
 
int overlapping (string s1, string s2)
 
string replace (string s, string what, string by)
 
static bool match_wildcard (string s, int spos, string w, int wpos)
 
bool match_wildcard (string s, string w)
 
int find_non_alpha (string s, int pos, bool forward)
 
array< stringtokenize (string s, string sep)
 
string recompose (array< string > a, string sep)
 
string trim_spaces_left (string s)
 
string trim_spaces_right (string s)
 
string trim_spaces (string s)
 
array< stringtrim_spaces (array< string > a)
 
static int find_longest (string s1, string s2, int &c1, int &c2)
 
static void find_common (string s1, string s2, int &c1, int &c2)
 
array< int > differences (string s1, string s2)
 the differences between two strings by identifying the common substrings and returning the different sections' indices.
 
int distance (string s1, string s2)
 a measure of difference (distance) between two strings.
 
void parse_length (string s, double &len, string &unit)
 Parses a string containing a length value and its unit.
 

Variables

static string il2_to_cork_string
 
static string cork_to_il2_string
 

Function Documentation

◆ is_iso_alpha() [1/2]

bool is_iso_alpha ( char c)

Checks if a character is an ISO alphabetic character.

Parameters
cThe character to be checked.
Returns
True if the character is an ISO alphabetic character; otherwise, returns False.

Definition at line 21 of file analyze.cpp.

21 {
22 int i= ((int) ((unsigned char) c));
23 return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) ||
24 ((i >= 128) && (i != 159) && (i != 189) && (i != 190) && (i != 191));
25}
The list class represents a linked list.
Definition list.hpp:48

◆ is_iso_locase()

bool is_iso_locase ( char c)

Checks if a character is an ISO lowercase alphabetic character.

Parameters
cThe character to check.
Returns
True if the character is ISO lowercase alphabetic, otherwise false.

Definition at line 28 of file analyze.cpp.

28 {
29 int code= (int) ((unsigned char) c);
30 return ((c >= 'a') && (c <= 'z')) || ((code >= 160) && (code < 189)) ||
31 (code >= 224);
32}

◆ is_iso_upcase()

bool is_iso_upcase ( char c)

Checks if a character is an ISO uppercase alphabetic character.

Parameters
cThe character to check.
Returns
True if the character is ISO uppercase alphabetic, otherwise false.

Definition at line 35 of file analyze.cpp.

35 {
36 int code= (int) ((unsigned char) c);
37 return ((c >= 'A') && (c <= 'Z')) || ((code >= 128) && (code < 159)) ||
38 ((code >= 192) && (code < 224));
39}

◆ is_alpha()

bool is_alpha ( string s)

Checks if a string contains only alphabetic characters.

Parameters
sThe string to check.
Returns
True if all characters in the string are alphabetic, otherwise false.

Definition at line 46 of file analyze.cpp.

46 {
47 int i;
48 if (N (s) == 0) return false;
49 for (i= 0; i < N (s); i++)
50 if (!is_alpha (s[i])) return false;
51 return true;
52}
bool is_alpha(string s)
Checks if a string contains only alphabetic characters.
Definition analyze.cpp:46
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170

◆ is_alphanum()

bool is_alphanum ( string s)

Definition at line 55 of file analyze.cpp.

55 {
56 int i;
57 if (N (s) == 0) return false;
58 for (i= 0; i < N (s); i++)
59 if (!(is_alpha (s[i]) || is_digit (s[i]))) return false;
60 return true;
61}
bool is_digit(char c)
Definition analyze.hpp:37

◆ is_locase_alpha()

bool is_locase_alpha ( string s)

Checks if a string contains only lowercase alphabetic characters.

Parameters
sThe string to check.
Returns
True if all characters in the string are lowercase alphabetic, otherwise false.

Definition at line 64 of file analyze.cpp.

64 {
65 int i;
66 if (N (s) == 0) return false;
67 for (i= 0; i < N (s); i++)
68 if (s[i] < 'a' || s[i] > 'z') return false;
69 return true;
70}

◆ is_iso_alpha() [2/2]

bool is_iso_alpha ( string s)

Checks if a string contains only ISO alphabetic characters.

Parameters
sThe string to check.
Returns
True if all characters in the string are ISO alphabetic, otherwise false.

Definition at line 73 of file analyze.cpp.

73 {
74 int i;
75 if (N (s) == 0) return false;
76 for (i= 0; i < N (s); i++)
77 if (!is_iso_alpha (s[i])) return false;
78 return true;
79}
bool is_iso_alpha(char c)
Checks if a character is an ISO alphabetic character.
Definition analyze.cpp:21

◆ is_numeric()

bool is_numeric ( string s)

Checks if a string contains only numeric characters.

Parameters
sThe string to check.
Returns
True if all characters in the string are numeric, otherwise false.

Definition at line 82 of file analyze.cpp.

82 {
83 int i;
84 if (N (s) == 0) return false;
85 for (i= 0; i < N (s); i++)
86 if (!is_numeric (s[i])) return false;
87 return true;
88}
bool is_numeric(string s)
Checks if a string contains only numeric characters.
Definition analyze.cpp:82

◆ upcase()

char upcase ( char s)

Converts a lowercase character to uppercase.

Parameters
cThe character to convert.
Returns
The uppercase version of the character if it is an ISO lowercase alphabetic character; otherwise, returns the original character.

Definition at line 95 of file analyze.cpp.

95 {
96 if (is_iso_locase (c)) return (char) (((int) ((unsigned char) c)) - 32);
97 else return c;
98}
bool is_iso_locase(char c)
Checks if a character is an ISO lowercase alphabetic character.
Definition analyze.cpp:28

◆ locase()

char locase ( char s)

Converts an uppercase character to lowercase.

Parameters
cThe character to convert.
Returns
The lowercase version of the character if it is an ISO uppercase alphabetic character; otherwise, returns the original character.

Definition at line 101 of file analyze.cpp.

101 {
102 if (is_iso_upcase (c)) return (char) (((int) ((unsigned char) c)) + 32);
103 else return c;
104}
bool is_iso_upcase(char c)
Checks if a character is an ISO uppercase alphabetic character.
Definition analyze.cpp:35

◆ closing_delimiter()

char closing_delimiter ( char c)

Finds the closing delimiter corresponding to the given opening delimiter.

Parameters
cThe opening delimiter character.
Returns
The corresponding closing delimiter if known, otherwise returns the original character.

Definition at line 107 of file analyze.cpp.

107 {
108 if (c == '{') return '}';
109 if (c == '(') return ')';
110 if (c == '[') return ']';
111 return c;
112}

◆ upcase_first()

string upcase_first ( string s)

Converts the first character of a string to uppercase.

Parameters
sThe string to convert.
Returns
A new string where the first character is converted to uppercase, if it is an ISO lowercase alphabetic character.

Definition at line 115 of file analyze.cpp.

115 {
116 if ((N (s) == 0) || (!is_iso_locase (s[0]))) return s;
117 return string ((char) (((int) ((unsigned char) s[0])) - 32)) * s (1, N (s));
118}

◆ locase_first()

string locase_first ( string s)

Converts the first character of a string to lowercase.

Parameters
sThe string to convert.
Returns
A new string where the first character is converted to lowercase, if it is an ISO uppercase alphabetic character.

Definition at line 121 of file analyze.cpp.

121 {
122 if ((N (s) == 0) || (!is_iso_upcase (s[0]))) return s;
123 return string ((char) (((int) ((unsigned char) s[0])) + 32)) * s (1, N (s));
124}

◆ upcase_all()

string upcase_all ( string s)

Converts all lowercase characters in a string to uppercase.

Parameters
sThe string to convert.
Returns
A new string where all ISO lowercase alphabetic characters are converted to uppercase.

Definition at line 127 of file analyze.cpp.

127 {
128 int i;
129 string r (N (s));
130 for (i= 0; i < N (s); i++)
131 if (!is_iso_locase (s[i])) r[i]= s[i];
132 else r[i]= (char) (((int) ((unsigned char) s[i])) - 32);
133 return r;
134}

◆ locase_all()

string locase_all ( string s)

Converts all uppercase characters in a string to lowercase.

Parameters
sThe string to convert.
Returns
A new string where all ISO uppercase alphabetic characters are converted to lowercase.

Definition at line 137 of file analyze.cpp.

137 {
138 int i;
139 string r (N (s));
140 for (i= 0; i < N (s); i++)
141 if (!is_iso_upcase (s[i])) r[i]= s[i];
142 else r[i]= (char) (((int) ((unsigned char) s[i])) + 32);
143 return r;
144}

◆ string_union()

string string_union ( string s1,
string s2 )

Union of two strings.

This function performs the union operation between two strings.

Parameters
s1The first string.
s2The second string.
Returns
A new string containing the union of s1 and s2.

Definition at line 151 of file analyze.cpp.

151 {
152 return string_minus (s1, s2) * s2;
153}
string string_minus(string s1, string s2)
Remove characters from one string that are in another string.
Definition analyze.cpp:156

◆ string_minus()

string string_minus ( string s1,
string s2 )

Remove characters from one string that are in another string.

Parameters
s1The first string.
s2The second string.
Returns
A new string containing s1 - s2.

Definition at line 156 of file analyze.cpp.

156 {
157 string r;
158 int i1, n1= N (s1), i2, n2= N (s2);
159 for (i1= 0; i1 < n1; i1++) {
160 for (i2= 0; i2 < n2; i2++)
161 if (s1[i1] == s2[i2]) break;
162 if (i2 == n2) r << s1[i1];
163 }
164 return r;
165}

◆ remove_prefix()

string remove_prefix ( string s,
string prefix )

Remove the prefix from s if matches.

Parameters
sthe string
prefixthe prefix
Returns
If the prefix matches, return s with prefix removed, otherwise, return s

Definition at line 168 of file analyze.cpp.

168 {
169 if (is_empty (s) || is_empty (prefix)) return s;
170 if (starts (s, prefix)) return s (N (prefix), N (s));
171 return s;
172}
bool starts(string s, const char *what)
Definition analyze.cpp:566
bool is_empty(string s)
Definition string.cpp:354

◆ remove_suffix()

string remove_suffix ( string s,
string suffix )

Remove the suffix from s if matches.

Parameters
sthe string
prefixthe suffix
Returns
If the suffix matches, return s with suffix removed, otherwise, return s

Definition at line 175 of file analyze.cpp.

175 {
176 if (is_empty (s) || is_empty (suffix)) return s;
177 if (ends (s, suffix)) return s (0, N (s) - N (suffix));
178 return s;
179}
bool ends(string s, const char *what)
Definition analyze.cpp:576
string suffix(url u, bool use_locase)
Definition url.cpp:381

◆ ispanish_to_spanish()

string ispanish_to_spanish ( string s)

Convert ispanish string to Spanish string.

Parameters
sThe ispanish string.
Returns
The converted Spanish string.

Definition at line 186 of file analyze.cpp.

186 {
187 int i, n= N (s);
188 string r;
189 for (i= 0; i < n; i++)
190 if ((s[i] == '\'') && ((i + 1) < n)) {
191 switch (s[i + 1]) {
192 case 'A':
193 r << '\301';
194 break;
195 case 'E':
196 r << '\311';
197 break;
198 case 'I':
199 r << '\315';
200 break;
201 case 'N':
202 r << '\321';
203 break;
204 case 'O':
205 r << '\323';
206 break;
207 case 'U':
208 r << '\332';
209 break;
210 case 'Y':
211 r << '\335';
212 break;
213 case 'a':
214 r << '\341';
215 break;
216 case 'e':
217 r << '\351';
218 break;
219 case 'i':
220 r << '\355';
221 break;
222 case 'n':
223 r << '\361';
224 break;
225 case 'o':
226 r << '\363';
227 break;
228 case 'u':
229 r << '\372';
230 break;
231 case 'y':
232 r << '\375';
233 break;
234 default:
235 r << '\'' << s[i + 1];
236 }
237 i++;
238 }
239 else r << s[i];
240 return r;
241}

◆ spanish_to_ispanish()

string spanish_to_ispanish ( string s)

Convert Spanish string to ispanish string.

Parameters
sThe Spanish string.
Returns
The converted ispanish string.

Definition at line 244 of file analyze.cpp.

244 {
245 int i, n= N (s);
246 string r;
247 for (i= 0; i < n; i++)
248 switch (s[i]) {
249 case '\301':
250 r << "'A";
251 break;
252 case '\311':
253 r << "'E";
254 break;
255 case '\315':
256 r << "'I";
257 break;
258 case '\321':
259 r << "'N";
260 break;
261 case '\323':
262 r << "'O";
263 break;
264 case '\332':
265 r << "'U";
266 break;
267 case '\335':
268 r << "'Y";
269 break;
270 case '\341':
271 r << "'a";
272 break;
273 case '\351':
274 r << "'e";
275 break;
276 case '\355':
277 r << "'i";
278 break;
279 case '\361':
280 r << "'n";
281 break;
282 case '\363':
283 r << "'o";
284 break;
285 case '\372':
286 r << "'u";
287 break;
288 case '\375':
289 r << "'y";
290 break;
291 default:
292 r << s[i];
293 }
294 return r;
295}

◆ igerman_to_german()

string igerman_to_german ( string s)

Convert igerman string to german string.

Parameters
sThe igerman string.
Returns
The converted german string.

Definition at line 298 of file analyze.cpp.

298 {
299 int i, n= N (s);
300 string r;
301 for (i= 0; i < n; i++)
302 if (s[i] == '\337') r << '\377';
303 else r << s[i];
304 return r;
305}

◆ german_to_igerman()

string german_to_igerman ( string s)

Convert german string to igerman string.

Parameters
sThe german string.
Returns
The converted igerman string.

Definition at line 308 of file analyze.cpp.

308 {
309 int i, n= N (s);
310 string r;
311 for (i= 0; i < n; i++)
312 if (s[i] == '\377') r << '\337';
313 else r << s[i];
314 return r;
315}

◆ il2_to_cork() [1/2]

static char il2_to_cork ( char c)
static

Definition at line 341 of file analyze.cpp.

341 {
342 int i= (int) ((unsigned char) c);
343 if (i < 128) return c;
344 return il2_to_cork_string[i - 128];
345}
static string il2_to_cork_string
Definition analyze.cpp:321

◆ cork_to_il2() [1/2]

static char cork_to_il2 ( char c)
static

Definition at line 348 of file analyze.cpp.

348 {
349 int i= (int) ((unsigned char) c);
350 if (i < 128) return c;
351 return cork_to_il2_string[i - 128];
352}
static string cork_to_il2_string
Definition analyze.cpp:330

◆ il2_to_cork() [2/2]

string il2_to_cork ( string s)

Definition at line 355 of file analyze.cpp.

355 {
356 int i, n= N (s);
357 string r (n);
358 for (i= 0; i < n; i++)
359 r[i]= il2_to_cork (s[i]);
360 return r;
361}
static char il2_to_cork(char c)
Definition analyze.cpp:341

◆ cork_to_il2() [2/2]

string cork_to_il2 ( string s)

Definition at line 364 of file analyze.cpp.

364 {
365 int i, n= N (s);
366 string r (n);
367 for (i= 0; i < n; i++)
368 r[i]= cork_to_il2 (s[i]);
369 return r;
370}
static char cork_to_il2(char c)
Definition analyze.cpp:348

◆ alpha_nr()

string alpha_nr ( int nr)

Generates an alphabetic string for an integer.

Parameters
nrThe integer to be converted to an alphabetic string.
Returns
A string representing the alphabetic character.

Definition at line 377 of file analyze.cpp.

377 {
378 if (nr < 0) return "-" * alpha_nr (-nr);
379 if (nr == 0) return "0";
380 if (nr <= 26) return string ((char) (((int) 'a') + nr - 1));
381 return alpha_nr ((nr - 1) / 26) * alpha_nr (((nr - 1) % 26) + 1);
382}
string alpha_nr(int nr)
Generates an alphabetic string for an integer.
Definition analyze.cpp:377

◆ Alpha_nr()

string Alpha_nr ( int nr)

Generates an uppercase alphabetic string for an integer.

Parameters
nrThe integer to be converted to an alphabetic string.
Returns
A string representing the uppercase alphabetic character.

Definition at line 385 of file analyze.cpp.

385 {
386 return upcase_all (alpha_nr (nr));
387}
string upcase_all(string s)
Converts all lowercase characters in a string to uppercase.
Definition analyze.cpp:127

◆ fnsymbol_nr()

string fnsymbol_nr ( int nr)

Generates footnote symbols for a given integer.

Parameters
nrThe integer to be converted to a footnote symbol.
Returns
A string representing the footnote symbol.

Definition at line 390 of file analyze.cpp.

390 {
391 if (nr < 0) nr= -nr;
392 string sym, r;
393 int i, m= (nr - 1) % 6, n= ((nr - 1) / 6) + 1;
394 switch (m) {
395 case 0:
396 sym= "<asterisk>";
397 break;
398 case 1:
399 sym= "<dag>";
400 break;
401 case 2:
402 sym= "<ddag>";
403 break;
404 case 3:
405 sym= "<paragraph>";
406 break;
407 case 4:
408 sym= "<endofline>";
409 break;
410 case 5:
411 sym= "||";
412 break;
413 }
414 for (i= 0; i < n; i++)
415 r << sym;
416 return r;
417}

◆ raw_quote()

string raw_quote ( string s)

Add quotes around a string to indicate it's a string, not a symbol.

This function is used for marking the label of a STRING tree as representing a string and not a symbol.

Parameters
sThe input string.
Returns
A new string with quotes around it.

Definition at line 420 of file analyze.cpp.

420 {
421 // Mark the label of a STRING tree as representing a string and not a symbol.
422 return "\"" * s * "\"";
423}

◆ raw_unquote()

string raw_unquote ( string s)

Remove quotes from a string label.

This function is used to get the string value of a STRING tree label representing a string.

Parameters
sThe input string.
Returns
The string without the quotes.

Definition at line 426 of file analyze.cpp.

426 {
427 // Get the string value of a STRING tree label representing a string.
428 if (is_quoted (s)) return s (1, N (s) - 1);
429 else return s;
430}
bool is_quoted(string s)
Definition string.cpp:408

◆ escape_sh()

string escape_sh ( string s)

Escape a string for use in shell scripts.

Parameters
sThe input string.
Returns
An escaped string.

Definition at line 437 of file analyze.cpp.

437 {
438#if (defined OS_MINGW || defined OS_WIN)
439 return raw_quote (s);
440#else
441 int i, n= N (s);
442 string r;
443 for (i= 0; i < n; i++)
444 switch (s[i]) {
445 case '(':
446 case ')':
447 case '<':
448 case '>':
449 case '?':
450 case '&':
451 case '$':
452 case '`':
453 case '\"':
454 case '\\':
455 case ' ':
456 r << '\\' << s[i];
457 break;
458 case '\n':
459 r << "\\n";
460 break;
461 default:
462 r << s[i];
463 }
464 return r;
465#endif
466}
string raw_quote(string s)
Add quotes around a string to indicate it's a string, not a symbol.
Definition analyze.cpp:420

◆ escape_generic()

string escape_generic ( string s)

Escape a string with generic escape sequences.

Parameters
sThe input string.
Returns
An escaped string.

Definition at line 469 of file analyze.cpp.

469 {
470 int i, n= N (s);
471 string r;
472 for (i= 0; i < n; i++) {
473 if ((s[i] == '\2') || (s[i] == '\5') || (s[i] == '\33')) r << '\33';
474 r << s[i];
475 }
476 return r;
477}

◆ escape_verbatim()

string escape_verbatim ( string s)

Escape a string to be displayed verbatim.

Parameters
sThe input string.
Returns
An escaped string.

Definition at line 480 of file analyze.cpp.

480 {
481 int i, n= N (s);
482 string r;
483 for (i= 0; i < n; i++) {
484 unsigned char c= (unsigned char) s[i];
485 if ((c == '\n') || (c == '\t')) r << ' ';
486 else if (((int) c) >= 32) r << s[i];
487 }
488 return r;
489}

◆ escape_spaces()

string escape_spaces ( string s)

Escape spaces in a string with a backslash.

Parameters
sThe input string.
Returns
A string with escaped spaces.

Definition at line 492 of file analyze.cpp.

492 {
493 int i, n= N (s);
494 string r;
495 for (i= 0; i < n; i++) {
496 unsigned char c= (unsigned char) s[i];
497 if (c == ' ') r << '\\';
498 r << c;
499 }
500 return r;
501}

◆ dos_to_better()

string dos_to_better ( string s)

Convert DOS line endings to more standard line endings.

Parameters
sThe input string.
Returns
A string with Unix-style line endings.

Definition at line 504 of file analyze.cpp.

504 {
505 int i, n= N (s);
506 string r;
507 for (i= 0; i < n; i++)
508 if (s[i] == '\015')
509 ;
510 else r << s[i];
511 return r;
512}

◆ unescape_guile()

string unescape_guile ( string s)

Unescape a Guile-syntax string.

Parameters
sThe input string.
Returns
A string with special characters unescaped.

Definition at line 515 of file analyze.cpp.

515 {
516 int i, n= N (s);
517 string r;
518 for (i= 0; i < n; i++) {
519 if (s[i] == '\\') {
520 if (i + 1 < n && s[i + 1] == '\\') {
521 r << "\\\\\\\\";
522 i+= 1;
523 }
524 else if (i + 3 < n && s[i + 1] == 'x' && is_hex_digit (s[i + 2]) &&
525 is_hex_digit (s[i + 3])) {
526 string e= s (i + 2, i + 4);
527 r << (unsigned char) lolly::data::from_hex (e);
528 i+= 3;
529 }
530 else r << s[i];
531 }
532 else r << s[i];
533 }
534 return r;
535}
bool is_hex_digit(char c)
Definition analyze.hpp:49
int from_hex(string s)
Converts a hexadecimal string to an integer.
Definition numeral.cpp:214

◆ test() [1/2]

bool test ( string s,
int i,
const char * test )

Definition at line 542 of file analyze.cpp.

542 {
543 int n= N (s), j= 0;
544 while (test[j] != '\0') {
545 if (i >= n) return false;
546 if (s[i] != test[j]) return false;
547 i++;
548 j++;
549 }
550 return true;
551}
bool test(string s, int i, const char *test)
Definition analyze.cpp:542

◆ test() [2/2]

bool test ( string s,
int i,
string test )

Definition at line 554 of file analyze.cpp.

554 {
555 int n= N (s), m= N (test), j= 0;
556 while (j < m) {
557 if (i >= n) return false;
558 if (s[i] != test[j]) return false;
559 i++;
560 j++;
561 }
562 return true;
563}

◆ starts() [1/2]

bool starts ( string s,
const char * what )

Definition at line 566 of file analyze.cpp.

566 {
567 return test (s, 0, what);
568}

◆ starts() [2/2]

bool starts ( string s,
const string what )

Definition at line 571 of file analyze.cpp.

571 {
572 return test (s, 0, what);
573}

◆ ends() [1/2]

bool ends ( string s,
const char * what )

Definition at line 576 of file analyze.cpp.

576 {
577 string r (what);
578 if (N (r) > N (s)) return false;
579 return s (N (s) - N (r), N (s)) == r;
580}

◆ ends() [2/2]

bool ends ( string s,
const string r )

Definition at line 583 of file analyze.cpp.

583 {
584 if (N (r) > N (s)) return false;
585 return s (N (s) - N (r), N (s)) == r;
586}

◆ read() [1/3]

bool read ( string s,
int & i,
const char * test )

Definition at line 589 of file analyze.cpp.

589 {
590 int n= N (s), j= 0, k= i;
591 while (test[j] != '\0') {
592 if (k >= n) return false;
593 if (s[k] != test[j]) return false;
594 j++;
595 k++;
596 }
597 i= k;
598 return true;
599}

◆ read() [2/3]

bool read ( string s,
string test )

Definition at line 602 of file analyze.cpp.

602 {
603 int i= 0;
604 return read (s, i, test);
605}
bool read(string s, int &i, const char *test)
Definition analyze.cpp:589

◆ read() [3/3]

bool read ( string s,
int & i,
string test )

Definition at line 608 of file analyze.cpp.

608 {
609 int n= N (s), m= N (test), j= 0, k= i;
610 while (j < m) {
611 if (k >= n) return false;
612 if (s[k] != test[j]) return false;
613 j++;
614 k++;
615 }
616 i= k;
617 return true;
618}

◆ read_line()

bool read_line ( string s,
int & i,
string & result )

Definition at line 621 of file analyze.cpp.

621 {
622 int start= i;
623 for (; i < N (s); i++) {
624 if (s[i] == '\n') {
625 result= s (start, i++);
626 return true;
627 }
628 }
629 result= s (start, i);
630 return false;
631}

◆ read_int()

bool read_int ( string s,
int & i,
int & result )

Definition at line 634 of file analyze.cpp.

634 {
635 int n= N (s), start= i;
636 result= 0;
637 if (i == n) return false;
638 if (s[i] == '-') {
639 if (i + 1 == n) return false;
640 if (!is_digit (s[i + 1])) return false;
641 i++;
642 }
643 else if (!is_digit (s[i])) return false;
644 while ((i < n) && is_digit (s[i]))
645 i++;
646 result= as_int (s (start, i));
647 return true;
648}
SI as_int(double x)
Converts a double to a signed integer, rounding to the nearest integer.
Definition basic.hpp:261

◆ read_double()

bool read_double ( string s,
int & i,
double & result )

Definition at line 651 of file analyze.cpp.

651 {
652 int n= N (s), start= i;
653 result= 0.0;
654 if (i == n) return false;
655 if (s[i] == '-') {
656 if (i + 1 == n) return false;
657 if (!is_numeric (s[i + 1])) return false;
658 i++;
659 }
660 else if (!is_numeric (s[i])) return false;
661 while ((i < n) && is_digit (s[i]))
662 i++;
663 if ((i < n) && (s[i] == '.')) i++;
664 while ((i < n) && is_digit (s[i]))
665 i++;
666 if ((i < n) && ((s[i] == 'e') || (s[i] == 'E'))) {
667 i++;
668 if ((i < n) && (s[i] == '-')) i++;
669 if ((i == n) || (!is_digit (s[i]))) {
670 i= start;
671 return false;
672 }
673 while ((i < n) && is_digit (s[i]))
674 i++;
675 }
676 result= as_double (s (start, i));
677 return true;
678}
double as_double(string s)
Definition string.cpp:279

◆ read_word()

bool read_word ( string s,
int & i,
string & result )

Definition at line 681 of file analyze.cpp.

681 {
682 int opos= i;
683 while (i < N (s) && is_alpha (s[i])) {
684 i++;
685 }
686 result= s (opos, i);
687 return i > opos;
688}

◆ is_whitespace()

bool is_whitespace ( string s)

Definition at line 691 of file analyze.cpp.

691 {
692 for (int i= 0; i < N (s); i++)
693 if (s[i] != ' ' && s[i] != '\t' && s[i] != '\n') return false;
694 return true;
695}

◆ skip_spaces()

void skip_spaces ( string s,
int & i )

Definition at line 698 of file analyze.cpp.

698 {
699 int n= N (s);
700 while ((i < n) && ((s[i] == ' ') || (s[i] == '\t')))
701 i++;
702}

◆ skip_whitespace()

void skip_whitespace ( string s,
int & i )

Definition at line 705 of file analyze.cpp.

705 {
706 int n= N (s);
707 while ((i < n) && ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')))
708 i++;
709}

◆ skip_line()

void skip_line ( string s,
int & i )

Definition at line 712 of file analyze.cpp.

712 {
713 int n= N (s);
714 while ((i < n) && (s[i] != '\n'))
715 i++;
716 if (i < n) i++;
717}

◆ skip_symbol()

void skip_symbol ( string s,
int & i )

Definition at line 720 of file analyze.cpp.

720 {
721 int n= N (s);
722 if (i < n) {
723 if (s[i] == '<') {
724 for (i++; i < n; i++)
725 if (s[i - 1] == '>') break;
726 }
727 else i++;
728 }
729}

◆ convert_tabs_to_spaces()

string convert_tabs_to_spaces ( string s,
int w )

Converts tabs in a string to spaces.

Parameters
sThe original string with tabs.
twThe tab width.
Returns
A new string with tabs replaced by spaces.

Definition at line 732 of file analyze.cpp.

732 {
733 int i= 0, ts= 0, n= N (s);
734 string r= "";
735 while (i < n) {
736 if (s[i] == '\t') {
737 r << string (' ', tw - ((i - ts) % tw));
738 ts= i + 1;
739 }
740 else if (s[i] == '\n') {
741 ts= i + 1;
742 r << s[i];
743 }
744 else r << s[i];
745 i++;
746 }
747 return r;
748}

◆ parse() [1/6]

void parse ( string s,
int & pos,
QI & ret )

Definition at line 755 of file analyze.cpp.

755 {
756 ret= (QI) s[pos++];
757}
char QI
Definition minmax.hpp:14

◆ parse() [2/6]

void parse ( string s,
int & pos,
QN & ret )

Definition at line 760 of file analyze.cpp.

760 {
761 ret= (QN) s[pos++];
762}
unsigned char QN
Definition minmax.hpp:15

◆ parse() [3/6]

void parse ( string s,
int & pos,
HI & ret )

Definition at line 765 of file analyze.cpp.

765 {
766 QI c1= (QI) s[pos++];
767 QN c2= (QN) s[pos++];
768 ret = (((HI) c1) << 8) + c2;
769}
short HI
Definition minmax.hpp:12

◆ parse() [4/6]

void parse ( string s,
int & pos,
HN & ret )

Definition at line 772 of file analyze.cpp.

772 {
773 QN c1= (QN) s[pos++];
774 QN c2= (QN) s[pos++];
775 ret = (((HN) c1) << 8) + c2;
776}
unsigned short HN
Definition minmax.hpp:13

◆ parse() [5/6]

void parse ( string s,
int & pos,
SI & ret )

Definition at line 779 of file analyze.cpp.

779 {
780 QI c1= (QI) s[pos++];
781 QN c2= (QN) s[pos++];
782 QN c3= (QN) s[pos++];
783 QN c4= (QN) s[pos++];
784 ret = (((((((SI) c1) << 8) + ((SI) c2)) << 8) + ((SI) c3)) << 8) + c4;
785}
int SI
Definition minmax.hpp:10

◆ parse() [6/6]

void parse ( string s,
int & pos,
SI *& a,
int len )

Definition at line 788 of file analyze.cpp.

788 {
789 int i;
791 for (i= 0; i < len; i++)
792 parse (s, pos, a[i]);
793}
void parse(string s, int &pos, QI &ret)
Definition analyze.cpp:755

◆ index_of()

int index_of ( string s,
char c )

Definition at line 800 of file analyze.cpp.

800 {
801 int s_N= N (s);
802 for (int i= 0; i < s_N; i++) {
803 if (s[i] == c) {
804 return i;
805 }
806 }
807 return -1;
808}

◆ search_forwards() [1/3]

int search_forwards ( array< string > what_list,
int pos,
string in )

Searches for a substring in a string starting from a specified position, in reverse.

Parameters
what_listThe substring to search for.
posThe starting position in the string to search from.
inThe string to search in.
Returns
Position where the substring was found, or -1 if not found.

Definition at line 811 of file analyze.cpp.

811 {
812 int n= N (in), na= N (a);
813 while (pos <= n) {
814 for (int i= 0; i < na; i++)
815 if (N (a[i]) > 0 && in[pos] == a[i][0] && test (in, pos, a[i]))
816 return pos;
817 pos++;
818 }
819 return -1;
820}

◆ search_forwards() [2/3]

int search_forwards ( string what,
int pos,
string in )

Searches for a substring in a string starting from a specified position.

Parameters
whatThe substring to search for.
posThe starting position in the string to search from.
inThe string to search in.
Returns
Position where the substring was found, or -1 if not found.

Definition at line 823 of file analyze.cpp.

823 {
824 int k= N (s), n= N (in);
825 if (k == 0) return pos;
826 char c= s[0];
827 while (pos + k <= n) {
828 if (in[pos] == c && test (in, pos, s)) return pos;
829 pos++;
830 }
831 return -1;
832}

◆ search_forwards() [3/3]

int search_forwards ( string what,
string in )

Searches for a substring in a string.

Parameters
whatThe substring to search for.
inThe string to search in.
Returns
Position where the substring was found, or -1 if not found.

Definition at line 835 of file analyze.cpp.

835 {
836 return search_forwards (s, 0, in);
837}
int search_forwards(array< string > a, int pos, string in)
Definition analyze.cpp:811

◆ occurs()

bool occurs ( string what,
string in )

Checks whether a substring occurs within another string.

Parameters
whatThe string to find.
inThe string in which to search.
Returns
True if the string occurs, otherwise false.

Definition at line 840 of file analyze.cpp.

840 {
841 return search_forwards (what, 0, in) >= 0;
842}

◆ contains() [1/2]

bool contains ( string s,
string what )

Definition at line 845 of file analyze.cpp.

845 {
846 return search_forwards (what, 0, s) >= 0;
847}

◆ contains() [2/2]

bool contains ( string s,
char c )

Definition at line 850 of file analyze.cpp.

850 {
851 int s_N= N (s);
852 for (int i= 0; i < s_N; i++) {
853 if (s[i] == c) {
854 return true;
855 }
856 }
857 return false;
858}

◆ search_backwards() [1/2]

int search_backwards ( string what,
int pos,
string in )

Searches for a substring in a string starting from a specified position, in reverse.

Parameters
sThe substring to search for.
posThe starting position in the string to search from.
inThe string to search in.
Returns
Position where the substring was found, or -1 if not found.

Definition at line 861 of file analyze.cpp.

861 {
862 while (pos >= 0) {
863 if (test (in, pos, s)) return pos;
864 pos--;
865 }
866 return -1;
867}

◆ search_backwards() [2/2]

int search_backwards ( string what,
string in )

Searches for a substring in a string, in reverse.

Parameters
sThe substring to search for.
inThe string to search in.
Returns
Position where the substring was found, or -1 if not found.

Definition at line 870 of file analyze.cpp.

870 {
871 return search_backwards (s, N (in) - N (s), in);
872}
int search_backwards(string s, int pos, string in)
Definition analyze.cpp:861

◆ count_occurrences()

int count_occurrences ( string what,
string in )

Counts the occurrences of a substring in a string.

Parameters
sThe substring to count.
inThe string to search in.
Returns
Number of occurrences of the substring.

Definition at line 875 of file analyze.cpp.

875 {
876 int count= 0;
877 int i= 0, next, n= N (in);
878 while (i < n) {
879 next= search_forwards (s, i, in);
880 if (next == -1) break;
881 count++;
882 i= next + 1;
883 }
884 return count;
885}

◆ overlapping()

int overlapping ( string s1,
string s2 )

Finds the length of the longest string that is both a suffix of the first string and a prefix of the second string.

Parameters
s1The first string.
s2The second string.
Returns
The length of the longest overlapping string.

Definition at line 888 of file analyze.cpp.

888 {
889 // return the longuest string being suffix of s1 and prefix of s2
890 int i= min (N (s1), N (s2)), n= N (s1);
891 while (i > 0) {
892 if (s1 (n - i, n) == s2 (0, i)) return i;
893 i--;
894 }
895 return 0;
896}
SI min(SI i, SI j)
Returns the minimum of two signed integers.
Definition minmax.hpp:27

◆ replace()

string replace ( string s,
string what,
string by )

Replaces all occurrences of a specific substring within a string.

Parameters
sThe original string.
whatThe substring to replace.
byThe string with which to replace the substring.
Returns
The new string with all occurrences of the substring replaced.

Definition at line 899 of file analyze.cpp.

899 {
900 int i, n= N (s);
901 string r;
902 for (i= 0; i < n;)
903 if (test (s, i, what)) {
904 r << by;
905 i+= N (what);
906 }
907 else {
908 r << s[i];
909 i++;
910 }
911 return r;
912}

◆ match_wildcard() [1/2]

static bool match_wildcard ( string s,
int spos,
string w,
int wpos )
static

Definition at line 915 of file analyze.cpp.

915 {
916 if (wpos == N (w)) return spos == N (s);
917 if (w[wpos] != '*')
918 return (spos < N (s)) && (s[spos] == w[wpos]) &&
919 match_wildcard (s, spos + 1, w, wpos + 1);
920 while ((wpos < N (w)) && (w[wpos] == '*'))
921 wpos++;
922 while (spos <= N (s)) {
923 if (match_wildcard (s, spos, w, wpos)) return true;
924 spos++;
925 }
926 return false;
927}
static bool match_wildcard(string s, int spos, string w, int wpos)
Definition analyze.cpp:915

◆ match_wildcard() [2/2]

bool match_wildcard ( string s,
string w )

Matches a string against a wildcard pattern.

Parameters
sThe string to match.
wThe wildcard pattern.
Returns
True if the string matches the wildcard pattern, otherwise false.

Definition at line 930 of file analyze.cpp.

930 {
931 return match_wildcard (s, 0, w, 0);
932}

◆ find_non_alpha()

int find_non_alpha ( string s,
int pos,
bool forward )

Finds the position of the first non-alphabetic character in a string.

Parameters
sThe string to search.
posThe position from which to start the search.
forwardTrue to search forward, false to search backward.
Returns
The position of the first non-alphabetic character; -1 if not found.

Definition at line 935 of file analyze.cpp.

935 {
936 if (forward) {
937 for (; pos < N (s); pos++)
938 if (!is_alpha (s[pos])) return pos;
939 }
940 else {
941 for (; pos > 0; pos--)
942 if (!is_alpha (s[pos - 1])) return pos - 1;
943 }
944 return -1;
945}

◆ tokenize()

array< string > tokenize ( string s,
string sep )

Splits a string into an array of strings based on a separator string.

Parameters
sThe string to split.
sepThe separator string.
Returns
An array of strings split based on the separator.

Definition at line 948 of file analyze.cpp.

948 {
949 int start= 0;
951 for (int i= 0; i < N (s);)
952 if (test (s, i, sep)) {
953 a << s (start, i);
954 i+= N (sep);
955 start= i;
956 }
957 else i++;
958 a << s (start, N (s));
959 return a;
960}

◆ recompose()

string recompose ( array< string > a,
string sep )

Joins an array of strings into a single string, separated by a specific string.

Parameters
aThe array of strings to join.
sepThe separator string.
Returns
A single string consisting of the array elements separated by the separator.

Definition at line 963 of file analyze.cpp.

963 {
964 string r;
965 for (int i= 0; i < N (a); i++) {
966 if (i != 0) r << sep;
967 r << a[i];
968 }
969 return r;
970}

◆ trim_spaces_left()

string trim_spaces_left ( string s)

Removes all leading spaces from a string.

Parameters
sThe string to trim.
Returns
The string without leading spaces.

Definition at line 973 of file analyze.cpp.

973 {
974 int start;
975 for (start= 0; start < N (s) && is_space (s[start]); start++)
976 ;
977 return s (start, N (s));
978}
bool is_space(char c)
Definition analyze.hpp:63

◆ trim_spaces_right()

string trim_spaces_right ( string s)

Removes all trailing spaces from a string.

Parameters
sThe string to trim.
Returns
The string without trailing spaces.

Definition at line 981 of file analyze.cpp.

981 {
982 int end;
983 for (end= N (s) - 1; end >= 0 && is_space (s[end]); end--)
984 ;
985 return s (0, end + 1);
986}

◆ trim_spaces() [1/2]

string trim_spaces ( string s)

Removes all leading and trailing spaces from a string.

Parameters
sThe string to trim.
Returns
The string without leading and trailing spaces.

Definition at line 989 of file analyze.cpp.

989 {
991}
string trim_spaces_left(string s)
Definition analyze.cpp:973
string trim_spaces_right(string s)
Definition analyze.cpp:981

◆ trim_spaces() [2/2]

array< string > trim_spaces ( array< string > a)

Removes all leading and trailing spaces from an array of strings.

Parameters
aThe array of strings to trim.
Returns
An array of strings with all leading and trailing spaces removed.

Definition at line 994 of file analyze.cpp.

994 {
995 array<string> b (N (a));
996 for (int i= 0; i < N (a); i++)
997 b[i]= trim_spaces (a[i]);
998 return b;
999}
string trim_spaces(string s)
Definition analyze.cpp:989
blackbox b[13]

◆ find_longest()

static int find_longest ( string s1,
string s2,
int & c1,
int & c2 )
static

Definition at line 1006 of file analyze.cpp.

1006 {
1007 int n1= N (s1), n2= N (s2), bc= 0, bl= 0, br= 0;
1008 for (c2= 0; c2 < n2; c2++)
1009 if (s1[c1] == s2[c2]) {
1010 int l= 0, r= 0;
1011 while (c1 + r < n1 && c2 + r < n2 && s1[c1 + r] == s2[c2 + r])
1012 r++;
1013 while (l < c1 && l < c2 && s1[c1 - l - 1] == s2[c2 - l - 1])
1014 l++;
1015 if (l + r > bl + br) {
1016 bc= c2;
1017 bl= l;
1018 br= r;
1019 }
1020 }
1021 if (bl + br > 0) {
1022 c1= c1 - bl;
1023 c2= bc - bl;
1024 }
1025 return bl + br;
1026}

◆ find_common()

static void find_common ( string s1,
string s2,
int & c1,
int & c2 )
static

Definition at line 1029 of file analyze.cpp.

1029 {
1030 int best_len= 0;
1031 c1= c2= 0;
1032 int n1= N (s1), n2= N (s2);
1033 if (n1 == 0 || n2 == 0) return;
1034 int t= min (min (n1, n2), 6);
1035 for (int k= 1; k < t; k++) {
1036 int a1= (k * n1) / t, a2= (k * n2) / t;
1037 int len= find_longest (s1, s2, a1, a2);
1038 if (len > best_len) {
1039 best_len= len;
1040 c1 = a1;
1041 c2 = a2;
1042 }
1043 }
1044}
static int find_longest(string s1, string s2, int &c1, int &c2)
Definition analyze.cpp:1006
blackbox t[13]

◆ differences()

array< int > differences ( string s1,
string s2 )

the differences between two strings by identifying the common substrings and returning the different sections' indices.

Parameters
s1The first string.
s2The second string.
Returns
An array containing sets of four integers:

Definition at line 1047 of file analyze.cpp.

1047 {
1048 int n1= N (s1), n2= N (s2);
1049 int i1= 0, i2= 0, j1= n1, j2= n2;
1050 while (i1 < j1 && i2 < j2 && s1[i1] == s2[i2]) {
1051 i1++;
1052 i2++;
1053 }
1054 while (i1 < j1 && i2 < j2 && s1[j1 - 1] == s2[j2 - 1]) {
1055 j1--;
1056 j2--;
1057 }
1058 if (i1 == i2 && j1 == j2) return array<int> ();
1059 if (i1 > 0 || i2 > 0 || j1 < n1 || j2 < n2) {
1060 array<int> r= differences (s1 (i1, j1), s2 (i2, j2));
1061 for (int k= 0; k < N (r); k+= 4) {
1062 r[k]+= i1;
1063 r[k + 1]+= i1;
1064 r[k + 2]+= i2;
1065 r[k + 3]+= i2;
1066 }
1067 return r;
1068 }
1069 else {
1070 int c1, c2;
1071 find_common (s1, s2, c1, c2);
1072 if (c1 == 0 && c2 == 0) {
1073 array<int> r;
1074 r << i1 << j1 << i2 << j2;
1075 return r;
1076 }
1077 else {
1078 array<int> r1= differences (s1 (0, c1), s2 (0, c2));
1079 array<int> r2= differences (s1 (c1, n1), s2 (c2, n2));
1080 for (int k= 0; k < N (r2); k+= 4) {
1081 r2[k]+= c1;
1082 r2[k + 1]+= c1;
1083 r2[k + 2]+= c2;
1084 r2[k + 3]+= c2;
1085 }
1086 r1 << r2;
1087 return r1;
1088 }
1089 }
1090}
array< int > differences(string s1, string s2)
the differences between two strings by identifying the common substrings and returning the different ...
Definition analyze.cpp:1047
static void find_common(string s1, string s2, int &c1, int &c2)
Definition analyze.cpp:1029

◆ distance()

int distance ( string s1,
string s2 )

a measure of difference (distance) between two strings.

Parameters
s1The first string.
s2The second string.
Returns
An integer representing the sum of lengths of all differing sections between the two strings.

Definition at line 1093 of file analyze.cpp.

1093 {
1094 int d= 0;
1096 for (int k= 0; k < N (r); k+= 4)
1097 d+= max (r[k + 1] - r[k], r[k + 3] - r[k + 2]);
1098 return d;
1099}
SI max(SI i, SI j)
Returns the maximum of two signed integers.
Definition minmax.hpp:40

◆ parse_length()

void parse_length ( string s,
double & len,
string & unit )

Parses a string containing a length value and its unit.

Parameters
[in]sThe string to parse, e.g., "12.34cm".
[out]lenThe parsed numerical value of the length.
[out]unitThe unit of the length as a string, e.g., "cm".

Definition at line 1106 of file analyze.cpp.

1106 {
1107 int start= 0;
1108 int i, n= N (s);
1109 for (i= start; i < n && !is_locase (s[i]); i++) {
1110 }
1111 string s1= s (start, i);
1112 string s2= s (i, n);
1113 if (is_double (s1) && (is_locase_alpha (s2) || is_empty (s2))) {
1114 len = as_double (s1);
1115 unit= s2;
1116 }
1117 else {
1118 len = 0.0;
1119 unit= "error";
1120 }
1121}
bool is_locase_alpha(string s)
Checks if a string contains only lowercase alphabetic characters.
Definition analyze.cpp:64
bool is_locase(char c)
Definition analyze.hpp:29
bool is_double(string s)
Definition string.cpp:376

Variable Documentation

◆ il2_to_cork_string

string il2_to_cork_string
static
Initial value:
=
"\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221"
"\222\223\224\225\226\227\230\231\232\233\234\235\236\237 \20\212 "
"\211\221\237¨\222\223\224\231‐\232\233 "
"\241˛\252´\251\261ˇ¸\262\263\264\271˝\272\273\217\301\302\200\304\210\202"
"\307\203\311\206\313\205\315\316\204\320\213\214\323\324\216\326."
"\220\227\332\226\334\335\225\377\257\341\342\240\344\250\242\347\243\351"
"\246\353\245\355\356\244\236\253\254\363\364\256\366/"
"\260\267\372\266\374\375\265 "

Definition at line 321 of file analyze.cpp.

◆ cork_to_il2_string

string cork_to_il2_string
static
Initial value:
=
"\303\241\306\310\317\314\312G\305\245\243\321\322 "
"\325\300\330\246\251\252\253\336\333\331Y\254\256\257II\360\247\343\261"
"\346\350\357\354\352g\345\265\263\361\362 "
"\365\340\370\266\271\272\273\376\373\371y\274\276\277i!?"
"LA\301\302A\304AA\307E\311E\313I\315\316I\320NO\323\324O\326OOU\332U\334"
"\335 "
"Sa\341\342a\344aa\347e\351e\353i\355\356i\360no\363\364o\366oou\372u\374"
"\375 \337"

Definition at line 330 of file analyze.cpp.