int main( void ) { printf( "From standard headers:\n" ); printsh( "char", SCHAR_MIN, UCHAR_MAX ); printsh( "short", SHRT_MIN, USHRT_MAX ); printsh( "int", INT_MIN, UINT_MAX ); printsh( "long", LONG_MIN, ULONG_MAX ); printf( "\nBy direct computation:\n" ); char_range(); short_range(); int_range(); long_range(); return 0; }
pgsRegexGen::pgsRegexGen(const wxString ®ex, const long &seed) : pgsObjectGen(seed), m_regex(regex), m_valid(true), m_string_gens(pgsVectorStringGen()) { wxLogScriptVerbose(wxT("REGEXGEN: %s"), m_regex.c_str()); // Transform regular expression into XML structure bool escape = false, first_regex = true, list = false; wxString result = wxT("<regexpressions>\n"); size_t i = 0; while (i < m_regex.Length()) { if (escape) { if (list == true) { result.Append(espace_xml_char(m_regex[i])); } else { if (!first_regex) result.Append(wxT(" </regex>\n")); else first_regex = false; result.Append(wxT(" <regex>\n <characters>")); result.Append(espace_xml_char(m_regex[i])); result.Append(wxT("</characters>\n")); } escape = false; } else if (list == true && m_regex[i] == wxT('-')) { if ((i + 1) < m_regex.Length()) { result.Append(char_range(m_regex[i - 1], m_regex[i + 1])); } } else if (m_regex[i] == wxT('[')) { if (!first_regex) result.Append(wxT(" </regex>\n")); else first_regex = false; result.Append(wxT(" <regex>\n <characters>")); list = true; } else if (m_regex[i] == wxT(']')) { result.Append(wxT("</characters>\n")); list = false; } else if (m_regex[i] == wxT('{')) { result.Append(wxT(" <range>")); list = true; } else if (m_regex[i] == wxT('}')) { result.Append(wxT("</range>\n")); list = false; } else if (m_regex[i] == wxT('\\')) { escape = true; } else { if (list == true) { result.Append(espace_xml_char(m_regex[i])); } else { if (!first_regex) result.Append(wxT(" </regex>\n")); else first_regex = false; result.Append(wxT(" <regex>\n <characters>")); result.Append(espace_xml_char(m_regex[i])); result.Append(wxT("</characters>\n")); } } ++i; } if (result != wxT("<regexpressions>\n")) result.Append(wxT(" </regex>\n")); result.Append(wxT("</regexpressions>\n")); wxLogScriptVerbose(wxT("REGEXGEN: %s"), result.c_str()); // Load this XML structure with the wxXmlDocument from wxWidgets wxStringInputStream input(result); wxXmlDocument doc; if (!doc.Load(input, wxT("UTF-8"), wxXMLDOC_KEEP_WHITESPACE_NODES)) { m_valid = false; } else { // Start processing the XML file if (doc.GetRoot()->GetName() != wxT("regexpressions")) { m_valid = false; } else { // Go through XML nodes wxXmlNode *xml_regexpressions = doc.GetRoot()->GetChildren(); while (xml_regexpressions && m_valid) { if (xml_regexpressions->GetName() == wxT("regex")) { wxXmlNode *xml_regex = xml_regexpressions->GetChildren(); pgsRegex regex; regex.set_first(1); while (xml_regex && m_valid) { if (xml_regex->GetName() == wxT("characters")) { wxString content = xml_regex->GetNodeContent(); for (size_t i = 0; i < content.Length(); i++) { regex.add_character(content[i]); } } else if (xml_regex->GetName() == wxT("range")) { wxString content = xml_regex->GetNodeContent(); wxRegEx ex(wxT("^([0-9]+)(,([0-9]+))?$")); wxASSERT(ex.IsValid()); if (ex.Matches(content)) { long min; ex.GetMatch(content, 1).ToLong(&min); regex.set_first(min); wxString smax = ex.GetMatch(content, 3); if (!smax.IsEmpty()) { long max; smax.ToLong(&max); regex.set_second(max); } } else { // m_valid = false; } } xml_regex = xml_regex->GetNext(); } m_string_gens.Add(pgsStringGen(regex.get_first(), regex.get_second(), 1, seed, regex.get_characters())); } xml_regexpressions = xml_regexpressions->GetNext(); } } } }