Skip to content

Commit

Permalink
iaNan(); find(KeyValue,,force); stringNotInSet(,,uppercase); Root::em…
Browse files Browse the repository at this point in the history
…pty() throws
  • Loading branch information
Vyacheslav Brover committed Dec 12, 2024
1 parent e5bd97e commit 104c200
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
16 changes: 14 additions & 2 deletions common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -1908,6 +1918,7 @@ void Root::saveFile (const string &fName) const



#if 0
void Root::trace (ostream& os,
const string& title) const
{
Expand All @@ -1917,6 +1928,7 @@ void Root::trace (ostream& os,
os << title << ": ";
saveText (os);
}
#endif



Expand Down
20 changes: 16 additions & 4 deletions common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ constexpr size_t no_index = numeric_limits<size_t>::max ();
static_assert ((size_t) 0 - 1 == no_index);

constexpr double NaN = numeric_limits<double>::quiet_NaN ();



// Global variables
Expand Down Expand Up @@ -165,6 +165,11 @@ void beep ();



template <typename T>
inline bool isNan (T x)
{ return x != x; }


// Comparison templates

template <typename T>
Expand Down Expand Up @@ -465,10 +470,14 @@ template <typename T /*container*/>
typedef map<string/*key*/,string/*value*/> 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;
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 104c200

Please sign in to comment.