api2021 part I #4

Merged
tomasz.sowa merged 67 commits from api2021 into master 2021-05-27 10:37:36 +02:00
Owner

merge some work from api2021 branch:

  • new Space struct (full json support)
  • PascalCase to snake_case in some places
  • CSVParser
  • MainOptionsParser
  • some tests
merge some work from api2021 branch: - new Space struct (full json support) - PascalCase to snake_case in some places - CSVParser - MainOptionsParser - some tests
tomasz.sowa added 67 commits 2021-05-27 10:36:59 +02:00
added: std::string to_str(...)
- utf8 auxiliary functions moved to utf8_private.h file
- in utf8.h are shown only functions available for consumers
- template functions has been moved to utf8_template.h (in utf8.h are only declarations)
  utf8_template.h is included at the end of utf8.h
- functions which take std::ostream changed to template (the stream is a template argument now)
now we have a correct model, some methods for setting/getting values and serialization to json
(no serialization to Space yet)
added to Space struct:
 void set_null();
 void set_empty_string();
 void set_empty_wstring();
 void set_empty_table();
 void set_empty_object();
 void clear();
(some minor chars escaping not ready yet)
- now there is only one Makefile in the root directory and we have only one pikotools.a lib file
- removed: mainparser
renamed: ParseFile() -> ParseJSONFile()
added: ParseSpaceFile(), ParseJSON(), ParseSpace()
also a '#' was not tested
without this such an input json (incorrect json string as there is no {} characters):
"key": "value"
would be parsed correctly: "key" would be parsed and the rest would be skipped
added in Space:
- some methods for adding values to an object, such as:
  Space & Space::add(const std::wstring & field, bool val) (bool, short, int, long, long long etc.)
- methods for creating lists:
  void Space::to_list(std::list<std::string> & output_list, bool clear_list) const
  bool Space::to_list(const wchar_t * field, std::list<std::string> & output_list, bool clear_list) const
- methods for converting a value from an object field:
  bool Space::to_bool(const wchar_t * field, bool default_value) const
- methods for testing strings:
  bool Space::is_equal(const char * val) const
  bool Space::is_equal(const std::string & val) const
  bool Space::is_equal(const wchar_t * val) const
  bool Space::is_equal(const std::wstring & val) const
- methods to get the raw pointer to a value from an object, such as:
  bool * Space::get_bool(const wchar_t * field)
  float * Space::get_float(const wchar_t * field)
- methods for finding a child space (used in Space format only)
  Space * Space::find_child_space(const wchar_t * name)
  Space & Space::find_add_child_space(const wchar_t * name)
- methods for testing a string value if a Space is a string or a table:
  bool has_value(const char * val) const;
  bool has_value(const std::string & val) const;
  bool has_value(const wchar_t * val) const;
  bool has_value(const std::wstring & val) const;
- methods for testing a string value in an object (testing a string or a table):
  bool has_value(const wchar_t * field, const char * val) const;
  bool has_value(const wchar_t * field, const std::string & val) const;
  bool has_value(const wchar_t * field, const wchar_t * val) const;
  bool has_value(const wchar_t * field, const std::wstring & val) const;
- methods for removing a child space:
  void remove_child_space(const wchar_t * name);
  void remove_child_space(const std::wstring & name);
  void remove_child_space(size_t index);
added to Space: some methods for searching a field with ignoring case:
Space * get_object_field_nc(const wchar_t * field)
Space * get_object_field_nc(const std::wstring & field);
const Space * get_object_field_nc(const wchar_t * field) const;
const Space * get_object_field_nc(const std::wstring & field) const;
Log & operator<<(morm::Model & model);
but we need some kind of a macro to allow this
Those characters were treated as invalid characters.

UTF8ToInt_FirstOctet incorrectly checked if the first octed is zero (after removing first bits).
This is a case only if the utf-8 character consists of two bytes. For 3 or 4 bytes
the first part can have all bits equal zero.
when converting from 'char' to 'int' we should first convert to 'unsigned char' and then to 'int'
- changed function names: PascalCase to snake_case
- templates functions moved to a seperate file (text_private.h)
- as a public api only available functions with char/wchar_t/std::string/std::wstring
- ToLower(...) changed to to_lower_emplace(...), similar ToUpper(...) to to_upper_emplace(...)
- added functions:
  std::string to_lower(const std::string & str);
  std::string to_upper(const std::string & str);
  and with std::wstring too
- functions with postfix 'NoCase' changed to 'nc'
currently only tests for convert/text functions
https://editorconfig.org/
if the same kind of object already existed
now we can:
- parse short options, those beginning with a hypnen '-'
- parse long options, those beginning with two hyphens '--'
- long options can have arguments in two forms:
  - either with an equal sign, e.g.: --opion-name=argument
  - or with a space, e.g: --option argument
    in the latter case we can have more than one argument, e.g: --option argument1 argument2
- parse non-option arguments, those after two hyphens to the end of a string, e.g: -- arg1 arg2
added methods:
Space(Space && space);
Space & operator=(Space && space);
void set(const Space & space);
void set(Space && space);
Space & add(const Space & space);
Space & add(Space && space);
Space & add(const wchar_t * field, const Space & space);
Space & add(const wchar_t * field, Space && space);
Space & add(const std::wstring & field, const Space & space);
Space & add(const std::wstring & field, Space && space);
and it cleared all values if not an empty object was provided to the set_space() method
- removed child_spaces and name pointers
- now a table with child spaces is created under "child_spaces" object field
- a name of the child space is stored in "name" field of the child object

added methods for manipulating with child spaces:
TableType * find_child_space_table()
bool child_spaces_empty()
size_t child_spaces_size()

Space * find_child_space(size_t table_index)
Space & add_child_space(const wchar_t * space_name)
Space & add_child_space(const std::wstring & space_name)

std::wstring * find_child_space_name()
std::wstring get_child_space_name()
bool is_child_space_name(const wchar_t * name)

added additional methods:
size_t str_size()
size_t wstr_size()
size_t object_size()
size_t table_size()
tomasz.sowa merged commit 848cdf9c03 into master 2021-05-27 10:37:36 +02:00
Sign in to join this conversation.
No description provided.