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 =
"";
55 default:
return LF_AT_END_STRING;
63{
return (to_check >= 32) && (to_check <= 126); }
66{
return (to_check ==
' ') || (to_check ==
'\t'); }
69{
return (to_check ==
'\n') || (to_check ==
'\r'); }
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') {
86 to_translate.
zap(i - 1, i - 1);
92 to_translate.
insert(i,
"\r");
113 for (
int i = 0; i < len; i++)
130 for (
int i = 0; i < len; i++)
143 for (
int i = 0; i < len; i++)
144 if (!
is_alpha(look_at[i]))
return false;
162 for (
int i = 0; i < len; i++)
172 return range_check(look_at,
'0',
'9') || (look_at ==
'-');
177 for (
int i = 0; i < len; i++) {
179 if ( (i > 0) && (look_at[i] ==
'-') )
return false;
196 indy = editing.
find(
'$');
199 for (q = indy + 1; q < editing.
length(); 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 void translate_CR_for_platform(basis::astring &to_translate)
flips embedded EOL characters for this platform's needs.
static bool is_identifier(char look_at)
returns true if "look_at" is a valid identifier character.
static bool is_hexadecimal(char look_at)
returns true if "look_at" is one of the hexadecimal characters.
static bool white_space_no_cr(char to_check)
reports if "to_check" is white space but not a carriage return.
static bool white_space(char to_check)
returns true if the character "to_check" is considered a white space.
static bool is_alpha(char look_at)
returns true if "look_at" is one of the alphabetical characters.
static bool is_hexadecimal(const char *look_at, int len)
returns true if "look_at" is all hexadecimal characters.
static bool is_printable_ascii(char to_check)
returns true if "to_check" is a normally visible ASCII character.
line_ending
Line endings is an enumeration of the separator character(s) used for text files.
@ LF_AT_END
Unix standard is LF_AT_END ("\n").
@ CRLF_AT_END
DOS standard is CRLF_AT_END ("\r\n").
@ NO_ENDING
No additional characters added as line endings.
static basis::astring substitute_env_vars(const basis::astring &text, bool leave_unknown=true)
resolves embedded environment variables in "text".
static bool is_alphanumeric(char look_at)
returns true if "look_at" is one of the alphanumeric characters.
static line_ending platform_eol()
provides the appropriate ending on the current OS platform.
static bool is_numeric(char look_at)
returns true if "look_at" is a valid numerical character.
static const char * eol_to_chars(line_ending ending)
returns the C string form for the "ending" value.
static bool is_eol(char to_check)
returns true if "to_check" is part of an end-of-line sequence.
static const char * platform_eol_to_chars()
provides the characters that make up this platform's line ending.
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.