diff --git a/common.cpp b/common.cpp index 96d4d39c..d0effec6 100644 --- a/common.cpp +++ b/common.cpp @@ -790,11 +790,21 @@ bool isLower (const string &s) size_t stringNotInSet (const string &s, - const string &charSet) + const string &charSet, + ebool uppercase) { FFOR (size_t, i, s. size ()) - if (! charInSet (s [i], charSet)) + { + char c = s [i]; + switch (uppercase) + { + case efalse: c = toLower (c); break; + case etrue: c = toUpper (c); break; + case enull: break; + } + if (! charInSet (c, charSet)) return i; + } return no_index; } @@ -1908,6 +1918,7 @@ void Root::saveFile (const string &fName) const +#if 0 void Root::trace (ostream& os, const string& title) const { @@ -1917,6 +1928,7 @@ void Root::trace (ostream& os, os << title << ": "; saveText (os); } +#endif diff --git a/common.hpp b/common.hpp index 1911f718..603cd635 100644 --- a/common.hpp +++ b/common.hpp @@ -116,7 +116,7 @@ constexpr size_t no_index = numeric_limits::max (); static_assert ((size_t) 0 - 1 == no_index); constexpr double NaN = numeric_limits::quiet_NaN (); - + // Global variables @@ -165,6 +165,11 @@ void beep (); +template + inline bool isNan (T x) + { return x != x; } + + // Comparison templates template @@ -465,10 +470,14 @@ template typedef map KeyValue; inline string find (const KeyValue& kv, - const string& key) + const string& key, + bool force) { const auto& it = kv. find (key); if (it == kv. end ()) + { if (force) + return key; throw runtime_error ("Key \"" + key + "\" is not found"); + } return it->second; } @@ -725,7 +734,8 @@ inline bool charInSet (char c, { return charSet. find (c) != string::npos; } size_t stringNotInSet (const string &s, - const string &charSet); + const string &charSet, + ebool uppercase); // Return: index in s which is not in charSet; may be no_index size_t strCountSet (const string &s, @@ -2086,15 +2096,17 @@ struct Root saveText (oss); return oss. str (); } +#if 0 void trace (ostream& os, const string& title) const; +#endif virtual void saveXml (Xml::File& /*f*/) const { throwf ("Root::saveXml() is not implemented"); } virtual Json* toJson (JsonContainer* /*parent_arg*/, const string& /*name_arg*/) const { throwf ("Root::toJson() is not implemented"); } virtual bool empty () const - { return true; } + { throwf ("Root::empty() is not implemented"); } virtual void clear () { throwf ("Root::clear() is not implemented"); } // Postcondition: empty()