Skip to content

Commit

Permalink
Cleanup: Redefined dsize; use Char classifications
Browse files Browse the repository at this point in the history
dsize is now always defined as a 64-bit unsigned integer. dsigsize is the signed variant.

Char offers character classification methods (e.g., isAlphaNumeric) using the_Foundation's functions.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 7da29eb commit 285781a
Show file tree
Hide file tree
Showing 41 changed files with 146 additions and 116 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/gl/gl_texmanager.cpp
Expand Up @@ -267,7 +267,7 @@ GLuint GL_PrepareFlaremap(res::Uri const &resourceUri)
if (resourceUri.path().length() == 1)
{
// Select a system flare by numeric identifier?
int number = resourceUri.path().toString().first() - '0';
int number = resourceUri.path().toString().first().delta('0');
if (number == 0) return 0; // automatic
if (number >= 1 && number <= 4)
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/resource/lightmaterialdecoration.cpp
Expand Up @@ -72,9 +72,9 @@ LightMaterialDecoration::AnimationStage::fromDef(Record const &stageDef)
{
// Select a system flare by numeric identifier?
if(haloTextureUri.path().length() == 1 &&
iswdigit(haloTextureUri.path().toString().first()))
haloTextureUri.path().toString().first().isNumeric())
{
haloTextureIndex = haloTextureUri.path().toString().first() - '0';
haloTextureIndex = haloTextureUri.path().toString().first().delta('0');
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/widgets/packageswidget.cpp
Expand Up @@ -193,7 +193,7 @@ DE_GUI_PIMPL(PackagesWidget)
btn->setText(_E(l) + tag);
btn->setActionFn([this, tag]() {
String terms = _owner.d->search->text();
if (!terms.isEmpty() && !iswspace(terms.last())) terms += " ";
if (!terms.isEmpty() && !terms.last().isSpace()) terms += " ";
terms += tag;
_owner.d->search->setText(terms);
});
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libs/comms/src/abstractlineeditor.cpp
Expand Up @@ -244,13 +244,13 @@ DE_PIMPL(AbstractLineEditor)

// First jump over any non-word chars.
//while (pos > 0 && !text[pos].isLetterOrNumber()) pos--;
while (iter.pos() > 0 && !iswalnum(*iter)) { --iter; }
while (iter.pos() > 0 && !(*iter).isAlphaNumeric()) { --iter; }

// At least move one character.
if (iter.pos() > 0) --pos;

// We're inside a word, jump to its beginning.
while (iter.pos() > 0 && iswalnum(*(iter - 1))) { --iter; }
while (iter.pos() > 0 && (*(iter - 1)).isAlphaNumeric()) { --iter; }

return iter.pos();
}
Expand All @@ -270,13 +270,13 @@ DE_PIMPL(AbstractLineEditor)
mb_iterator iter = iterator(cursor);

// If inside a word, jump to its end.
while (iter != last && iswalnum(*iter))
while (iter != last && (*iter).isAlphaNumeric())
{
iter++;
}

// Jump over any non-word chars.
while (iter != last && !iswalnum(*iter))
while (iter != last && !(*iter).isAlphaNumeric())
{
iter++;
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/comms/src/lexicon.cpp
Expand Up @@ -69,7 +69,7 @@ String Lexicon::additionalWordChars() const
bool Lexicon::isWordChar(Char ch) const
{
// Default word characters.
if (iswalnum(ch)) return true;
if (ch.isAlphaNumeric()) return true;
return d->extraChars.contains(ch);
}

Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/comms/src/monospacelinewrapping.cpp
Expand Up @@ -69,7 +69,7 @@ void MonospaceLineWrapping::wrapTextToWidth(const String &text, WrapWidth maxWid

// Find a good break point.
const mb_iterator lineEnding = end;
while (!iswspace(*end))
while (!(*end).isSpace())
{
--end;
--curLineWidth;
Expand All @@ -89,7 +89,7 @@ void MonospaceLineWrapping::wrapTextToWidth(const String &text, WrapWidth maxWid
}
else
{
if (iswspace(*end)) ++end;
if ((*end).isSpace()) ++end;
_lines << WrappedLine(CString(begin, end), curLineWidth);
begin = end;
}
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libs/core/include/de/core/log.h
Expand Up @@ -480,7 +480,8 @@ class DE_PUBLIC LogEntry : public Lockable, public ISerializable
void setValue(uint32_t i);
void setValue(int64_t i);
void setValue(uint64_t i);
void setValue(ddouble d);
void setValue(ddouble d);
inline void setValue(size_t i) { setValue(uint64_t(i)); }
void setValue(void const *p);
void setValue(const char *s);
void setValue(const std::string &s);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/data/cstring.h
Expand Up @@ -97,7 +97,7 @@ class DE_PUBLIC CString
String upper() const;
std::string toStdString() const { updateEnd(); return {_range.start, _range.end}; }

static size_t npos;
static dsize npos;

private:
mutable Rangecc _range;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libs/core/include/de/data/hash.h
Expand Up @@ -20,6 +20,7 @@
#define LIBCORE_HASH_H

#include <unordered_map>
#include "../libcore.h"

namespace de {

Expand Down Expand Up @@ -54,6 +55,7 @@ class Hash : public std::unordered_map<Key, Value, HashFn, KeyEqual>
using Base::find;

bool isEmpty() const { return empty(); }
inline dsize size() const { return dsize(Base::size()); }
inline int sizei() const { return int(Base::size()); }

iterator insert(const Key &key, const Value &value)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/data/ibytearray.h
Expand Up @@ -42,7 +42,7 @@ class DE_PUBLIC IByteArray
typedef dsize Offset;

/// Difference between two offsets.
typedef dlong Delta;
typedef dsigsize Delta;

/// The elements of the array must be of type Byte.
typedef dbyte Byte;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libs/core/include/de/data/list.h
Expand Up @@ -68,13 +68,14 @@ class List : public std::vector<T>
using Base::cend;
using Base::push_back;
using Base::emplace_back;
using Base::size;

void pop_front() { removeFirst(); } // slow...
void push_front(const T &v) { prepend(v); } // slow...

// Qt style methods:

inline int count() const { return sizei(); }
inline dsize size() const { return dsize(Base::size()); }
inline int sizei() const { return int(Base::size()); }
void clear() { Base::clear(); }
bool isEmpty() const { return Base::size() == 0; }
Expand Down
6 changes: 4 additions & 2 deletions doomsday/libs/core/include/de/data/map.h
Expand Up @@ -20,6 +20,7 @@
#define LIBCORE_MAP_H

#include <map>
#include "../libcore.h"

namespace de {

Expand Down Expand Up @@ -48,8 +49,9 @@ class Map : public std::map<Key, Value, Compare>
using Base::cbegin;
using Base::cend;

inline bool isEmpty() const { return Base::empty(); }
inline int sizei() const { return int(Base::size()); }
inline bool isEmpty() const { return Base::empty(); }
inline dsize size() const { return dsize(Base::size()); }
inline int sizei() const { return int(Base::size()); }

iterator insert(const Key &key, const Value &value)
{
Expand Down
22 changes: 12 additions & 10 deletions doomsday/libs/core/include/de/libcore.h
Expand Up @@ -821,14 +821,10 @@ typedef int64_t dint64; ///< 64-bit signed integer.
typedef uint64_t duint64; ///< 64-bit unsigned integer.
typedef float dfloat; ///< 32-bit floating point number.
typedef double ddouble; ///< 64-bit floating point number.
typedef size_t dsize; // Likely unsigned long.
#if defined (_MSC_VER)
typedef long long dsigsize;
#else
typedef ssize_t dsigsize;
#endif
typedef long dlong;
typedef unsigned int uint;
typedef uint64_t dsize;
typedef int64_t dsigsize;

typedef unsigned int uint; // for convenience

class DE_PUBLIC Char
{
Expand All @@ -842,13 +838,19 @@ class DE_PUBLIC Char
inline explicit operator bool() const { return _ch != 0; }
inline operator uint32_t() const { return _ch; }
inline uint32_t unicode() const { return _ch; }
inline int delta(Char from) const { return int(_ch) - int(from._ch); }

Char &operator=(const Char &) = default;
Char &operator=(Char &&) = default;

Char upper() const;
Char lower() const;

bool isSpace() const;
bool isAlpha() const;
bool isNumeric() const;
bool isAlphaNumeric() const;

private:
uint32_t _ch;
};
Expand Down Expand Up @@ -912,8 +914,8 @@ typedef unsigned char dbyte;
typedef unsigned int duint; // 32-bit
typedef float dfloat;
typedef double ddouble;
typedef size_t dsize;
typedef long dlong;
typedef uint64_t dsize;
typedef int64_t dsigsize;

#endif // !__cplusplus

Expand Down
6 changes: 3 additions & 3 deletions doomsday/libs/core/include/de/widgets/constantrule.h
Expand Up @@ -92,9 +92,9 @@ ConstantRule::Builder<Type>::operator RefArg<Rule>() const
return RefArg<Rule>(new ConstantRule(_number));
}

typedef ConstantRule::Builder<int> Const;
typedef ConstantRule::Builder<dsize> Constu;
typedef ConstantRule::Builder<float> Constf;
typedef ConstantRule::Builder<int32_t> Const;
typedef ConstantRule::Builder<uint32_t> Constu;
typedef ConstantRule::Builder<float> Constf;

} // namespace de

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/core/commandline.cpp
Expand Up @@ -394,7 +394,7 @@ void CommandLine::parse(String const &cmdLine)

String word;

while (i != cmdLine.end() && (quote || !iswspace(*i)))
while (i != cmdLine.end() && (quote || !(*i).isSpace()))
{
bool copyChar = true;
if (!quote)
Expand Down
13 changes: 6 additions & 7 deletions doomsday/libs/core/src/core/monospacelogsinkformatter.cpp
Expand Up @@ -131,10 +131,9 @@ struct TabFiller
// Find the widest position for this tab stop by checking all lines.
for (int idx = 0; idx < fills.sizei(); ++idx)
{
String const &ln = fills.at(idx);
int w = (idx > 0? minIndent : 0);
//for (int i = 0; i < ln.size(); ++i)
iConstForEach(String, i, ln)
const String &ln = fills.at(idx);
int w = (idx > 0 ? minIndent : 0);
iConstForEach(String, i, ln) // TODO: Use the C++ mb_iterator instead.
{
if (i.value == '\t')
{
Expand All @@ -145,7 +144,7 @@ struct TabFiller
// continue to the tab-replacing phase.
goto replaceTabs;
}
if (i.value == '+' || (i.value - 'a') == stop)
if (i.value == '+' || Char(i.value).delta('a') == stop)
{
// This is it.
tabWidth = max(tabWidth, w);
Expand Down Expand Up @@ -285,8 +284,8 @@ StringList MonospaceLogSinkFormatter::logEntryToTextLines(LogEntry const &entry)

// The wrap indentation will be determined dynamically based on the content
// of the line.
dsize wrapIndent = wstring::npos;
dsize nextWrapIndent = wstring::npos;
// dsize wrapIndent = wstring::npos;
// dsize nextWrapIndent = wstring::npos;

const String minIndentStr{dsize(_minimumIndent), ' '};

Expand Down
6 changes: 3 additions & 3 deletions doomsday/libs/core/src/data/cstring.cpp
Expand Up @@ -62,7 +62,7 @@ dsize CString::indexOf(const char *cStr, size_t from) const
{
if (from >= size_t(_range.size())) return npos;
const char *pos = iStrStrN(_range.start + from, cStr, _range.size() - from);
return pos ? (pos - _range.start) : npos;
return pos ? dsize(pos - _range.start) : npos;
}

dsize CString::indexOf(const String &str, size_t from) const
Expand All @@ -81,7 +81,7 @@ CString CString::leftStrip() const
{
CString s(*this);
mb_iterator i = s.begin();
while (!s.isEmpty() && iswspace(*i))
while (!s.isEmpty() && (*i).isSpace())
{
s._range.start = ++i;
}
Expand All @@ -94,7 +94,7 @@ CString CString::rightStrip() const
mb_iterator i = s.end();
while (!s.isEmpty())
{
if (iswspace(*--i))
if ((*--i).isSpace())
{
s._range.end = i;
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/libs/core/src/data/json.cpp
Expand Up @@ -56,7 +56,7 @@ class JSONParser

void skipWhite()
{
while (!atEnd() && iswspace(*pos)) _previous = pos++;
while (!atEnd() && (*pos).isSpace()) _previous = pos++;
}

bool atEnd() const
Expand Down Expand Up @@ -126,7 +126,7 @@ class JSONParser
{
return parseString();
}
else if (c == '-' || iswdigit(c))
else if (c == '-' || c.isNumeric())
{
return parseNumber();
}
Expand Down Expand Up @@ -254,7 +254,7 @@ class JSONParser
str.append(c);
c = nextNoSkip();
}
for (; iswdigit(c); c = nextNoSkip())
for (; c.isNumeric(); c = nextNoSkip())
{
str.append(c);
}
Expand All @@ -264,7 +264,7 @@ class JSONParser
str.append(c);
hasDecimal = true;
c = nextNoSkip();
for (; iswdigit(c); c = nextNoSkip())
for (; c.isNumeric(); c = nextNoSkip())
{
str.append(c);
}
Expand All @@ -279,7 +279,7 @@ class JSONParser
str.append(c);
c = nextNoSkip();
}
for (; iswdigit(c); c = nextNoSkip())
for (; c.isNumeric(); c = nextNoSkip())
{
str.append(c);
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/data/pathtreenode.cpp
Expand Up @@ -177,7 +177,7 @@ static int matchName(const CString &string, const CString &pattern)
continue;
}

if (towlower(*pat) != towlower(*in))
if ((*pat).lower() != (*in).lower())
{
// A mismatch. Hmm. Go back to a previous '*'.
//while (pat >= pattern && *pat != QChar('*')) { --pat; }
Expand Down

0 comments on commit 285781a

Please sign in to comment.