Skip to content

Commit

Permalink
libcore: RegExp capture as CString; hash function for Id
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 6c57539 commit e78c0aa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
14 changes: 11 additions & 3 deletions doomsday/libs/core/include/de/core/id.h
Expand Up @@ -102,9 +102,7 @@ class DE_PUBLIC Id : public ISerializable, public LogEntry::Arg::Base
Type _id;
};

//DE_PUBLIC QTextStream &operator << (QTextStream &os, Id const &id);

//inline uint qHash(Id const &id) { return id; }
DE_PUBLIC std::ostream &operator<<(std::ostream &os, Id const &id);

/**
* Utility for declaring identifiers that are initially uninitialized.
Expand All @@ -118,4 +116,14 @@ class DE_PUBLIC NoneId : public Id

} // namespace de

namespace std
{
template<>
struct hash<de::Id> {
std::size_t operator()(const de::Id &key) const {
return hash<uint32_t>()(key.asUInt32());
}
};
}

#endif // LIBCORE_ID_H
24 changes: 11 additions & 13 deletions doomsday/libs/core/include/de/data/binarytree.h
Expand Up @@ -132,7 +132,7 @@ class BinaryTree
return *_parent;
}
/// @throw MissingParentError Attempted with no parent linked.
throw MissingParentError("BinaryTree::parent", QString("No parent is linked"));
throw MissingParentError("BinaryTree::parent", "No parent is linked");
}

/**
Expand Down Expand Up @@ -255,8 +255,8 @@ class BinaryTree
return **adr;
}
/// @throw MissingChildError Attempted with no child linked.
throw MissingChildError("BinaryTree::child", QString("No %1 child is linked")
.arg(which? "Left" : "Right"));
throw MissingChildError("BinaryTree::child",
stringf("No %s child is linked", which ? "Left" : "Right"));
}

/**
Expand Down Expand Up @@ -331,7 +331,7 @@ class BinaryTree
* Retrieve the height of this tree.
* @return Tree height.
*/
size_t height() const
dsize height() const
{
if (!isLeaf())
{
Expand Down Expand Up @@ -409,7 +409,7 @@ class BinaryTree
* @return @c 0= iff all callbacks complete wholly else the return value of the
* callback last made.
*/
int traversePreOrder(int (*callback) (BinaryTree &, void *), void *parameters = 0)
int traversePreOrder(int (*callback) (BinaryTree &, void *), void *parameters = nullptr)
{
if (!callback) return false; // Continue iteration.

Expand Down Expand Up @@ -444,7 +444,7 @@ class BinaryTree
* @return @c 0= iff all callbacks complete wholly else the return value of the
* callback last made.
*/
int traverseInOrder(int (*callback) (BinaryTree &, void *), void *parameters = 0)
int traverseInOrder(int (*callback) (BinaryTree &, void *), void *parameters = nullptr)
{
if (!callback) return false; // Continue iteration.

Expand Down Expand Up @@ -479,7 +479,7 @@ class BinaryTree
* @return @c 0= iff all callbacks complete wholly else the return value of the
* callback last made.
*/
int traversePostOrder(int (*callback) (BinaryTree &, void *), void *parameters = 0)
int traversePostOrder(int (*callback) (BinaryTree &, void *), void *parameters = nullptr)
{
if (!callback) return false; // Continue iteration.

Expand All @@ -504,14 +504,12 @@ class BinaryTree
*/
String summary() const
{
String text = String("%1 nodes, %2 leafs")
.arg(nodeCount())
.arg(leafCount());
String text = String::format("%i nodes, %i leafs", nodeCount(), leafCount());
if (!isLeaf())
{
text += String(" (balance is %1:%2)")
.arg(hasRight()? right().height() : 0)
.arg(hasLeft() ? left ().height() : 0);
text += stringf(" (balance is %zu:%zu)",
hasRight() ? right().height() : 0,
hasLeft() ? left().height() : 0);
}
return text;
}
Expand Down
7 changes: 4 additions & 3 deletions doomsday/libs/core/include/de/data/regexp.h
Expand Up @@ -19,7 +19,7 @@
#ifndef LIBCORE_REGEXP_H
#define LIBCORE_REGEXP_H

#include "../String"
#include "../CString"
#include <c_plus/regexp.h>

namespace de {
Expand All @@ -34,8 +34,9 @@ class DE_PUBLIC RegExpMatch
const char *begin() const;
const char *end() const;

void clear();
String captured(int index = 0) const;
void clear();
String captured(int index = 0) const;
CString capturedCStr(int index = 0) const;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/include/de/libcore.h
Expand Up @@ -351,8 +351,8 @@
#if defined(__cplusplus) && !defined(DE_C_API_ONLY)
namespace de {

DE_PUBLIC void debug(const char *, ...);
DE_PUBLIC void warning(const char *, ...);
DE_PUBLIC void debug (const char *, ...);
DE_PUBLIC void warning (const char *, ...);

/**
* Formats a string using the standard C printf() syntax.
Expand Down
7 changes: 7 additions & 0 deletions doomsday/libs/core/src/data/regexp.cpp
Expand Up @@ -47,6 +47,13 @@ String RegExpMatch::captured(int index) const
return String::take(captured_RegExpMatch(&match, index));
}

CString RegExpMatch::capturedCStr(int index) const
{
iRangecc range;
capturedRange_RegExpMatch(&match, index, &range);
return range;
}

RegExp::RegExp(const String &expression, Sensitivity cs)
{
_d = new_RegExp(expression, cs == CaseSensitive? caseSensitive_RegExpOption
Expand Down

0 comments on commit e78c0aa

Please sign in to comment.