<heading>class xml_element : xml_node</heading>
<para>
The class xml_element is derived from the class xml_node and adds properties
-soecific to XML ekements.
+specific to XML elements.
</para>
+<description>
+<item tag="xml_element()">
+The default constructor creates an empty xml element.
+</item>
+<item tag="xml_element(xml doc)">
+Construct an element from the XML document. The xml_element object will be the root element
+of the XML document.
+</item>
+<item tag="std::vector<xml_element> operator[](String tagname);">
+Find the child elements with the specified tagname.
+</item>
+</description>
</section>
/* */
- char& operator[](int i); // Individual character access
+ char& operator[](size_t i); // Individual character access
int operator~() const // Length of the String
{
substring String::operator()(int start, int len)
{
substring sub;
+ size_t _start;
- if (start >= strlen(p->s) || start + len >= strlen(p->s))
+ _start = start; // Proper type conversion
+
+ if (_start >= strlen(p->s) || _start + len >= strlen(p->s))
{
throw StringException("Substring Out of bounds: ("
+ String(start) + ", " + String(len) + ")");
// TODO: boundary check.
// TODO: Assignment to an individual character does not decouple references (BUG)
-char& String::operator[](int i)
+char& String::operator[](size_t i)
{
if (i >= strlen(p->s))
{
d.month = pd->month;
d.day = pd->day;
}
+
+ if (t.hours == -1)
+ t.hours = 0;
+ if (t.minutes == -1)
+ t.minutes = 0;
+ if (t.seconds == -1)
+ t.seconds = 0;
}
UTC Now(bool local)
check_PROGRAMS = string_assign string_basics string_compare string_cat string_substring string_regex \
date_assign date_parse date_compare date_arithmetic date_attributes date_check_today \
hour_assign hour_parse hour_compare hour_arithmetic hour_check_now \
- utc_assign utc_compare utc_arithmetic \
+ utc_assign utc_parse utc_compare utc_arithmetic utc_convert \
integer_assign integer_factorial integer_fibonacci integer_pow64 integer_modulo \
xml_file xml_find xml_node xml_elem \
configuration_read configuration_find
hour_now : hour_check_now
utc_assign_SOURCES = utc_assign.cpp
+utc_parse_SOURCES = utc_parse.cpp
utc_compare_SOURCES = utc_compare.cpp
utc_arithmetic_SOURCES = utc_arithmetic.cpp
+utc_convert_SOURCES = utc_convert.cpp
integer_assign_SOURCES = integer_assign.cpp
integer_factorial_SOURCES = integer_factorial.cpp tInteger.cpp
// Out of bounds
try
{
- c = s1[-1];
+ c = s1[7];
std::cout << "Seventh character of " << s1 << " char(" << (int)c << ")\n";
}
catch (StringException se)
The length of "abcde" is 5
First character of abcde 'a'
Fourth character of abcde 'd'
-String exception: Out of bounds: -1
+String exception: Out of bounds: 7
After "abcde"[2] = 'Z' : abZde
String exception: Out of bounds: 5
After "abcde"[5] = 'X' : abZde
--- /dev/null
+/*******************************************************
+ * Unit test for the UTC class
+ *
+ * test conversion and formatting of UTC objects
+ ******************************************************
+ *
+ */
+
+#include "date.h"
+#include <assert.h>
+
+int main()
+{
+ String formatted;
+
+ date d1(15, 9, 2002);
+ hour h1(15, 23, 46);
+
+ UTC u1(d1, h1);
+
+ std::cout << "Contructor with date = 15-9-2002, hour = 15:23:46: " << u1 << "\n";
+ formatted = u1.format();
+ std::cout << "Formatted with default format: " << formatted << "\n";
+ assert(formatted == "2002-09-15 15:23:46");
+
+
+ String s3("23-10-2019 23:45");
+ UTC u3(s3);
+
+ std::cout << "Contructor from String " << s3 << " : " << u3 << "\n";
+ formatted = u3.format();
+ std::cout << "Formatted with default format: " << formatted << "\n";
+ assert(formatted == "2019-10-23 23:45:00");
+
+
+ return 0;
+}
+
--- /dev/null
+Contructor with date = 15-9-2002, hour = 15:23:46: 15-09-2002 15:23:46
+Formatted with default format: 2002-09-15 15:23:46
+Contructor from String 23-10-2019 23:45 : 23-10-2019 23:45:00
+Formatted with default format: 2019-10-23 23:45:00
+PASS utc_convert (exit status: 0)
--- /dev/null
+/****************************************************************
+ * Unit test for the UTC class
+ *
+ * test the date and time parser that converts String to UTC
+ ***************************************************************
+ *
+ */
+
+#include "date.h"
+#include <assert.h>
+
+int main()
+{
+ UTC u0;
+ String the_date;
+
+
+ the_date = "20120208 113456";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+ assert(hour(u0) == hour(11, 34, 56));
+
+ the_date = "2012-02-08";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+ assert(hour(u0) == hour(0, 0, 0));
+
+ the_date = "2012-02-08 11:34";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+ assert(hour(u0) == hour(11, 34, 0));
+
+ the_date = "2012-02-08 11:34:56";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+ assert(hour(u0) == hour(11, 34, 56));
+
+ the_date = "2012 02 08 11.34.56";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+ assert(hour(u0) == hour(11, 34, 56));
+
+ the_date = "08-02-2012";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+
+ the_date = "02/08/2012";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+
+ the_date = "Feb 8 2012";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+
+ the_date = "2012 Feb 8";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+
+ the_date = "8 FEB 2012";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+
+ the_date = "2012 8 feb";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+
+ the_date = "8 February 2012 15:00";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, 2012));
+ assert(hour(u0) == hour(15, 0, 0));
+
+ the_date = "Sun Jun 16 13:02:56 CEST 2019"; // A UNIX date string
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(16, 6, 2019));
+ assert(hour(u0) == hour(13, 2, 56));
+
+ // Without a year: year = -1
+ the_date = "8 February";
+ u0 = UTC(the_date);
+ std::cout << "String \"" << the_date << "\" converts to: \"" << u0 << "\"\n";
+ assert(date(u0) == date(8, 2, -1));
+
+ // TODO: test for invalid dates and syntax errors
+
+ return 0;
+}
+
--- /dev/null
+String "20120208 113456" converts to: "08-02-2012 11:34:56"
+String "2012-02-08" converts to: "08-02-2012 00:00:00"
+String "2012-02-08 11:34" converts to: "08-02-2012 11:34:00"
+String "2012-02-08 11:34:56" converts to: "08-02-2012 11:34:56"
+String "2012 02 08 11.34.56" converts to: "08-02-2012 11:34:56"
+String "08-02-2012" converts to: "08-02-2012 00:00:00"
+String "02/08/2012" converts to: "08-02-2012 00:00:00"
+String "Feb 8 2012" converts to: "08-02-2012 00:00:00"
+String "2012 Feb 8" converts to: "08-02-2012 00:00:00"
+String "8 FEB 2012" converts to: "08-02-2012 00:00:00"
+String "2012 8 feb" converts to: "08-02-2012 00:00:00"
+String "8 February 2012 15:00" converts to: "08-02-2012 15:00:00"
+String "Sun Jun 16 13:02:56 CEST 2019" converts to: "16-06-2019 13:02:56"
+String "8 February" converts to: "08-02--1 00:00:00"
+PASS utc_parse (exit status: 0)
--- /dev/null
+Reading XML file xml_test01.xml
+Root element is doc
+Root node type is 1
+Node 0 type is 3
+Node 0 name is text
+Node 1 type is 1
+Node 1 name is titlepage
+Node 2 type is 3
+Node 2 name is text
+Node 3 type is 1
+Node 3 name is toc
+Node 4 type is 3
+Node 4 name is text
+Node 5 type is 1
+Node 5 name is chapter
+Node 6 type is 3
+Node 6 name is text
+Node 7 type is 1
+Node 7 name is chapter
+Node 8 type is 3
+Node 8 name is text
+Node 9 type is 1
+Node 9 name is chapter
+Node 10 type is 3
+Node 10 name is text
+Node 11 type is 0
+Node 11 name is
+PASS xml_node (exit status: 0)