BasicUtilities Namespace Reference

A collection of utility methods. More...


Functions

Str trim (Str str)
 Trim string of leading and trailing blanks.
void split_file_name (Str file_name_in, Str &dir, Str &file_name, bool &is_relative)
 Splits a file name into a directory string and base file name.
int string_to_int (const Str &str, bool &ok)
 Converts a string to an integer.
bool is_int (const Str &str)
 Tests if a string to an integer.
double string_to_double (const Str &str, bool &ok)
 Converts a string to a real (double).
bool is_double (const Str &str)
 Tests if a string to a double.
bool string_to_bool (const Str &str, bool &ok)
 Converts a string to a logical bool.
bool is_bool (const Str &str)
 Tests if a string to a bool.
Str bool_to_string (bool this_bool)
 Converts a bool to a string.
Str int_to_string (const int i, bool &ok)
 Converts an integer to a string.
Str double_to_string (const double r, bool &ok)
 Converts an real double to a string.
Str str_to_upper (const Str &str_in)
 Converts a string to upper case.
Str str_to_lower (const Str &str_in)
 Converts a string to lower case.
Str add_parens (const Str &sub_expression, const Str &expression, int i0)
 Adds parentheses "(...)" around a sub-expression that will be inserted in a larger expression.
Str add_parens (const Str &sub_expression, int op_level)
 Adds parentheses "(...)" around an expression that will be inserted in a larger expression.
Str to_xml_string (Str str_in)
 Converts characters "&", "<", ">", and '"' to their XML equivalents: "&amp;", "&lt;", etc.
Str from_xml_string (Str str_in)
 Converts XML character entity reference references like "&amp;", <", etc to their character equivalents: "&", "<", ">", "'", and '"'.
Str str_pop (StrList &str_list)
 Pops the front item of the list and returns it.
Str element_val (StrList &s_list, int index)
 Returns the string value of an element in a StrList indexed by index.
bool found (StrList &s_list, const Str &item)
 Returns true if an item is in the list.
StrListIter find (StrList &s_list, const Str &item)
 Returns an iterator to a matching item in a list.
StrList list_copy (StrListIter begin, StrListIter end)
 Returns a copy of a list: [begin, end).
bool found_value (StrMap &string_map, const Str &item)
 Returns true if an item is a value in a map.
bool get_taylor_exponents (const Str &exp_str, IntVec &exp_vec)
 Decomposes an exponent string like "0 2 1 0 0 0" into its component numbers.
bool splitXMLName (const Str &_name, Str &uri, Str &prefix, Str &loc_name)
 Splits an XML name into a URI, prefix and local name components.


Detailed Description

A collection of utility methods.

Author:
David Sagan


Function Documentation

string BasicUtilities::add_parens ( const Str &  sub_expression,
int  op_level 
)

Adds parentheses "(...)" around an expression that will be inserted in a larger expression.

The op_level argument indicates the level of the operators in the larger expression to either: op_level = 1: Add parantheses if there is a "+" or "-" operator outside of any parentheses. For example: An expression like "(a/b) + c" needs parentheses but the expression "a * (b + c)" does not. op_level = 2: Add parantheses if there is a "+", "-", "/", or "*" operator outside of any parentheses. For example: An expression like "a * c" needs parentheses but the expression "a^2" does not. side of the insertion point. This is useful when adding an expression to a larger expression.

Parameters:
sub_expression Input expression
op_level Level of the operators in the larger expression to either side of the insertion point.
Returns:
Expression with parentheses added if needed.

Definition at line 374 of file BasicUtilities.cpp.

string BasicUtilities::add_parens ( const Str &  sub_expression,
const Str &  expression,
int  i0 
)

Adds parentheses "(...)" around a sub-expression that will be inserted in a larger expression.

Parameters:
sub_expression Sub-expression to be inserted.
expression Larger expression.
i0 Insertion point.
Returns:
Sub-expression with parentheses if needed.

Definition at line 346 of file BasicUtilities.cpp.

string BasicUtilities::bool_to_string ( bool  this_bool  ) 

Converts a bool to a string.

Parameters:
this_bool Bool input.
Returns:
Encoded string.

Definition at line 264 of file BasicUtilities.cpp.

string BasicUtilities::double_to_string ( const double  r,
bool &  ok 
)

Converts an real double to a string.

Parameters:
r Double input.
ok True if conversion OK. False otherwise.
Returns:
Encoded string.

Definition at line 313 of file BasicUtilities.cpp.

std::string BasicUtilities::element_val ( StrList &  s_list,
int  index 
)

Returns the string value of an element in a StrList indexed by index.

Parameters:
s_list List of strings.
index Index of element in s_list.
Returns:
String value. If index is out-of-range then return "".

Definition at line 73 of file BasicUtilities.cpp.

StrListIter BasicUtilities::find ( StrList &  s_list,
const Str &  item 
)

Returns an iterator to a matching item in a list.

Parameters:
s_list List of strings.
item String to search for.
Returns:
Iterator to the item. s_list.end() if not found.

Definition at line 477 of file BasicUtilities.cpp.

bool BasicUtilities::found ( StrList &  s_list,
const Str &  item 
)

Returns true if an item is in the list.

Parameters:
s_list List of strings.
item String to search for.
Returns:
True if item is in the list. False otherwise.

bool BasicUtilities::found_value ( StrMap &  string_map,
const Str &  item 
)

Returns true if an item is a value in a map.

Parameters:
string_map Key/Value map.
item String to search for.
Returns:
True if item is a value in the map. False otherwise.

Definition at line 470 of file BasicUtilities.cpp.

string BasicUtilities::from_xml_string ( Str  str_in  ) 

Converts XML character entity reference references like "&amp;", <", etc to their character equivalents: "&", "<", ">", "'", and '"'.

Parameters:
str_in Input XML string.
Returns:
Converted string.

Definition at line 432 of file BasicUtilities.cpp.

bool BasicUtilities::get_taylor_exponents ( const Str &  exp_str,
IntVec &  exp_vec 
)

Decomposes an exponent string like "0 2 1 0 0 0" into its component numbers.

Parameters:
exp_str Input exponent string.
exp_vec Output vector of 6 exponents.
Returns:
True if decomposition is successful. False otherwise.

Definition at line 509 of file BasicUtilities.cpp.

string BasicUtilities::int_to_string ( const int  i,
bool &  ok 
)

Converts an integer to a string.

Parameters:
i Integer input.
ok True if conversion OK. False otherwise.
Returns:
Encoded string.

Definition at line 289 of file BasicUtilities.cpp.

bool BasicUtilities::is_bool ( const Str &  str  ) 

Tests if a string to a bool.

Parameters:
str String to convert.
Returns:
True if the string is a bool. False otherwise. "" returns false.

Definition at line 272 of file BasicUtilities.cpp.

bool BasicUtilities::is_double ( const Str &  str  ) 

Tests if a string to a double.

Parameters:
str String to convert.
Returns:
True if the string is a double. False otherwise. "" returns false.

Definition at line 224 of file BasicUtilities.cpp.

bool BasicUtilities::is_int ( const Str &  str  ) 

Tests if a string to an integer.

Parameters:
str String to convert.
Returns:
True if the string is an integer. False otherwise. "" returns false.

Definition at line 186 of file BasicUtilities.cpp.

StrList BasicUtilities::list_copy ( StrListIter  begin,
StrListIter  end 
)

Returns a copy of a list: [begin, end).

Parameters:
begin Beginning of copy region
end End of copy region. end is not copied!
Returns:
Copy of the region

Definition at line 488 of file BasicUtilities.cpp.

void BasicUtilities::split_file_name ( Str  file_name_in,
Str &  dir,
Str &  file_name,
bool &  is_relative 
)

Splits a file name into a directory string and base file name.

Parameters:
file_name_in The input file name.
dir Set to the directory with trailing '/'.
file_name The base file name stripped of the directory string.
is_relative Set True if the directory name is relative to the default directory (as opposed to an absolute path name).

Definition at line 103 of file BasicUtilities.cpp.

bool BasicUtilities::splitXMLName ( const Str &  _name,
Str &  uri,
Str &  prefix,
Str &  loc_name 
)

Splits an XML name into a URI, prefix and local name components.

Parameters:
_name A local/qualified/universal/or full name.
uri URI part of xml_name.
prefix Prefix part of the name
loc_name Local part of xml_name.
prefix_found Set false if a prefix was not defined. Set true otherwise. That is, set false when _name is a local-name or a universal-name.
Returns:
Set false if _name is malformed. EG: unmatched "{...}" found. Set true otherwise

Definition at line 535 of file BasicUtilities.cpp.

string BasicUtilities::str_pop ( StrList &  str_list  ) 

Pops the front item of the list and returns it.

Parameters:
str_list The list of strings.
Returns:
The front string.

Definition at line 498 of file BasicUtilities.cpp.

string BasicUtilities::str_to_lower ( const Str &  str_in  ) 

Converts a string to lower case.

Parameters:
str_in Input string.
Returns:
Lowercased version of input string.

Definition at line 335 of file BasicUtilities.cpp.

string BasicUtilities::str_to_upper ( const Str &  str_in  ) 

Converts a string to upper case.

Parameters:
str_in Input string.
Returns:
Uppercased version of input string.

Definition at line 398 of file BasicUtilities.cpp.

bool BasicUtilities::string_to_bool ( const Str &  str,
bool &  ok 
)

Converts a string to a logical bool.

Parameters:
str String to convert.
ok True if conversion OK. False otherwise. "" returns ok = false.
Returns:
logical value.

Definition at line 241 of file BasicUtilities.cpp.

double BasicUtilities::string_to_double ( const Str &  str,
bool &  ok 
)

Converts a string to a real (double).

Parameters:
str String to convert.
ok True if conversion OK. False otherwise. "" returns ok = false.
Returns:
real value.

Definition at line 201 of file BasicUtilities.cpp.

int BasicUtilities::string_to_int ( const Str &  str,
bool &  ok 
)

Converts a string to an integer.

Parameters:
str String to convert.
ok True if conversion OK. False otherwise. "" returns ok = false.
Returns:
Integer value.

Definition at line 163 of file BasicUtilities.cpp.

string BasicUtilities::to_xml_string ( Str  str_in  ) 

Converts characters "&", "<", ">", and '"' to their XML equivalents: "&amp;", "&lt;", etc.

Notice that single quote is not converted since it is assumed that double quotes will be used to bound the string.

Parameters:
str_in Input string.
Returns:
XML string.

Definition at line 409 of file BasicUtilities.cpp.

string BasicUtilities::trim ( Str  str  ) 

Trim string of leading and trailing blanks.

Parameters:
str String to be trimmed.
Returns:
String with blanks trimmed.

Definition at line 84 of file BasicUtilities.cpp.


Generated on Fri Feb 12 15:47:59 2010 for Universal Accelerator Parser by  doxygen 1.5.7