24 using namespace basis;
27 #define LOG(prf) printf("%s\n", basis::astring(prf).s())
36 #elif defined(__WIN32__)
47 static const char *CRLF_AT_END_STRING =
"\r\n";
48 static const char *LF_AT_END_STRING =
"\n";
49 static const char *NO_ENDING_STRING =
"";
52 case CRLF_AT_END:
return CRLF_AT_END_STRING;
53 case NO_ENDING:
return NO_ENDING_STRING;
55 default:
return LF_AT_END_STRING;
59 const char *parser_bits::platform_eol_to_chars()
60 {
return eol_to_chars(platform_eol()); }
62 bool parser_bits::is_printable_ascii(
char to_check)
63 {
return (to_check >= 32) && (to_check <= 126); }
65 bool parser_bits::white_space_no_cr(
char to_check)
66 {
return (to_check ==
' ') || (to_check ==
'\t'); }
69 {
return (to_check ==
'\n') || (to_check ==
'\r'); }
71 bool parser_bits::white_space(
char to_check)
72 {
return white_space_no_cr(to_check) ||
is_eol(to_check); }
74 void parser_bits::translate_CR_for_platform(
astring &to_translate)
77 bool last_was_lf =
false;
78 for (
int i = 0; i <= to_translate.
end(); i++) {
79 if (to_translate[i] ==
'\r') {
80 if (last_was_lf)
continue;
82 }
else if (to_translate[i] ==
'\n') {
84 if (plat_eol != CRLF_AT_END) {
86 to_translate.
zap(i - 1, i - 1);
90 if (plat_eol == CRLF_AT_END) {
92 to_translate.
insert(i,
"\r");
104 bool parser_bits::is_hexadecimal(
char look_at)
111 bool parser_bits::is_hexadecimal(
const char *look_at,
int len)
113 for (
int i = 0; i < len; i++)
118 bool parser_bits::is_hexadecimal(
const astring &look_at,
int len)
119 {
return is_hexadecimal(look_at.
observe(), len); }
121 bool parser_bits::is_alphanumeric(
char look_at)
128 bool parser_bits::is_alphanumeric(
const char *look_at,
int len)
130 for (
int i = 0; i < len; i++)
131 if (!is_alphanumeric(look_at[i]))
return false;
135 bool parser_bits::is_alphanumeric(
const astring &look_at,
int len)
136 {
return is_alphanumeric(look_at.
observe(), len); }
138 bool parser_bits::is_alpha(
char look_at)
141 bool parser_bits::is_alpha(
const char *look_at,
int len)
143 for (
int i = 0; i < len; i++)
144 if (!is_alpha(look_at[i]))
return false;
148 bool parser_bits::is_alpha(
const astring &look_at,
int len)
149 {
return is_alpha(look_at.
observe(), len); }
151 bool parser_bits::is_identifier(
char look_at)
159 bool parser_bits::is_identifier(
const char *look_at,
int len)
161 if (is_numeric(look_at[0]))
return false;
162 for (
int i = 0; i < len; i++)
163 if (!is_identifier(look_at[i]))
return false;
167 bool parser_bits::is_identifier(
const astring &look_at,
int len)
168 {
return is_identifier(look_at.
observe(), len); }
170 bool parser_bits::is_numeric(
char look_at)
172 return range_check(look_at,
'0',
'9') || (look_at ==
'-');
175 bool parser_bits::is_numeric(
const char *look_at,
int len)
177 for (
int i = 0; i < len; i++) {
178 if (!is_numeric(look_at[i]))
return false;
179 if ( (i > 0) && (look_at[i] ==
'-') )
return false;
184 bool parser_bits::is_numeric(
const astring &look_at,
int len)
185 {
return is_numeric(look_at.
observe(), len); }
196 indy = editing.
find(
'$');
199 for (q = indy + 1; q < editing.
length(); q++) {
200 if (!parser_bits::is_identifier(editing[q]))
209 if (value_found.
t()) {
210 editing.
zap(indy, q - 1);
211 editing.
insert(indy, value_found);
219 editing.
zap(indy, q - 1);
Provides a dynamically resizable ASCII character string.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
void insert(int position, const astring &to_insert)
Copies "to_insert" into "this" at the "position".
int end() const
returns the index of the last (non-null) character in the string.
int length() const
Returns the current length of the string.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
virtual const char * observe() const
observes the underlying pointer to the zero-terminated string.
static astring get(const astring &variable_name)
looks up the "variable_name" in the current environment variables.
static bool is_hexadecimal(const char *look_at, int len)
returns true if "look_at" is all hexadecimal characters.
line_ending
Line endings is an enumeration of the separator character(s) used for text files.
The guards collection helps in testing preconditions and reporting errors.
bool range_check(const type &c, const type &low, const type &high)
Returns true if "c" is between "low" and "high" inclusive.
bool negative(const type &a)
negative returns true if "a" is less than zero.
bool is_eol(char to_check)