* @param prefix NULL or a prefix of the output
* @return <code>buffer.str()</code> (for chaining)
*/
-const char* ReByteBuffer::status(ReByteBuffer& buffer, const char* prefix){
+const char* ReByteBuffer::status(ReByteBuffer& buffer, const char* prefix) const{
if (prefix != NULL)
buffer.append(prefix);
buffer.append("capacity:").appendInt(m_capacity)
bool splice(size_t ix, size_t replacedLength, const Byte* source, size_t length);
bool startsWith(const Byte* head, size_t headLength = -1,
const bool ignoreCase = false) const;
- const char* status(ReByteBuffer& buffer, const char* prefix = NULL);
+ const char* status(ReByteBuffer& buffer, const char* prefix = NULL) const;
/** @brief Returns the buffer content as C string.
* This is exactly the same result as from <code>getBuffer()</code>.
* @return The internal used buffer.
* @param stream OUT: output stream
* @param prefix NULL or a string which is written first
*/
-void ReHashList::dump(FILE* stream, const char* prefix){
+void ReHashList::dump(FILE* stream, const char* prefix) const{
if (prefix != NULL)
fprintf(stream, "%s\n", prefix);
ReArrayPosition position;
* @param prefix NULL or a prefix of the output
* @return <code>buffer.str()</code> (for chaining)
*/
-const char* ReHashList::status(ReByteBuffer& buffer, const char* prefix){
+const char* ReHashList::status(ReByteBuffer& buffer, const char* prefix) const{
if (prefix != NULL)
buffer.append(prefix).append("\n", 1);
m_keys.status(buffer, "keys: ");
virtual ~ReHashList();
public:
void clear();
- void dump(FILE* stream, const char* prefix = NULL);
+ void dump(FILE* stream, const char* prefix = NULL) const;
bool get(const Byte* key, size_t keyLength, ReByteBuffer& value) const;
bool get(const ReByteBuffer& key, ReByteBuffer& value) const;
bool next(ReArrayPosition& position, ReByteBuffer* key, ReByteBuffer* val) const;
void put(const char* key, const char* value);
void put(const ReByteBuffer& key, const ReByteBuffer& value);
void setCapacity(int maxKeys, int keySpace, int contentSpace);
- const char* status(ReByteBuffer& buffer, const char* prefix = NULL);
+ const char* status(ReByteBuffer& buffer, const char* prefix = NULL) const;
protected:
int find(const Byte* key, size_t length) const;
/**
* Writes the content to a stream.
*
- * @param fp target file pointer
+ * @param fp target file pointer
+ * @param prefix NULL or a introduction
*/
-void ReSeqArray::dump(FILE* fp) const{
+void ReSeqArray::dump(FILE* fp, const char* prefix) const{
ReByteBuffer buffer;
Tag tag;
+ if (prefix != NULL)
+ fprintf(fp, "%s\n", prefix);
for (int ix = 0; ix < (int) count(); ix++){
get(ix, buffer, &tag);
fprintf(fp, "%d: (%ld) [%d] %s\n", ix, (int64_t) tag, (int) buffer.length(),
* @param prefix NULL or a prefix of the output
* @return <code>buffer.str()</code> (for chaining)
*/
-const char* ReSeqArray::status(ReByteBuffer& buffer, const char* prefix){
+const char* ReSeqArray::status(ReByteBuffer& buffer, const char* prefix) const{
if (prefix != NULL)
buffer.append(prefix);
buffer.append("age: ").appendInt(m_age).append("\n");
inline Index count() const {
return m_list.length() / m_entrySize;
}
- void dump(FILE* fp) const;
+ void dump(FILE* fp, const char* prefix) const;
Index find(const Byte* toFind, size_t length, Tag* tag = NULL) const;
bool get(Index index, ReByteBuffer& value, Tag* tag = NULL) const;
+ /** Returns whether the comparisons inside the list are case insensitive.
+ * @return <code>true</code> the comparisons inside the list are case insensitive
+ */
+ bool ignoreCase() const {
+ return m_ignoreCase;
+ }
/** Returns whether the list is sorted automatically.
* Note: comparison is controlled by <code>m_ignoreCase</code>.
* @return <code>true</code> the byte sequences will be sorted
bool isSorted() const {
return m_sorted;
}
- /** Returns whether the comparisons inside the list are case insensitive.
- * @return <code>true</code> the comparisons inside the list are case insensitive
- */
- bool ignoreCase() const {
- return m_ignoreCase;
- }
void remove(Index index);
void set(Index index, const Byte* source, size_t sourceLength, Tag tag);
void setCapacity(int maxIndices, int maxStringSpace);
void setSorted(bool onNotOff);
void setIgnoreCase(bool onNotOff);
void sort();
- const char* status(ReByteBuffer& buffer, const char* prefix = NULL);
+ const char* status(ReByteBuffer& buffer, const char* prefix = NULL) const;
protected:
/** @brief Returns a pointer of the content buffer.
* @return A pointer of the first byte of the content buffer.
add(-1, source.strOf(ii), source.sizeOf(ii), source.tagOf(ii));
return *this;
}
+
+/** @brief Tests the equality with another instance.
+ *
+ * Compares the internal array of strings with another instance.
+ * Two instances are equal when the number of strings are equal
+ * and the n.th string is equal to the n.th string in the other instance.
+ *
+ * @param toCompare the other instance which will be compared
+ *
+ * @return true: the other instance is equal. false: Otherwise
+ */
+bool ReStringList::equal(const ReStringList& toCompare) const{
+ bool rc = count() == toCompare.count() && firstDiff(toCompare) == -1;
+ return rc;
+}
+
+/** @brief Returns the index of the first different string.
+ *
+ * Compares the internal array of strings with another instance
+ *
+ * @param toCompare the other instance which will be compared
+ *
+ * @return -1: the instances are equal. Otherwise: the index of the first different string
+ *
+ */
+int ReStringList::firstDiff(const ReStringList& toCompare) const{
+ int rc = -1;
+ int count1 = count();
+ int count2 = toCompare.count();
+ int maxIx = count1 > count2 ? count2 : count1;
+ for (size_t ix = 0; rc == -1 && (int) ix < maxIx; ix++){
+ if (sizeOf(ix) != toCompare.sizeOf(ix)
+ || strcmp(strOf(ix), toCompare.strOf(ix)) != 0)
+ rc = (int) ix;
+ }
+ if (rc == -1 && count1 != count2)
+ rc = maxIx;
+ return rc;
+}
+
/** @brief Inserts a string at a given index.
*
* If the index exceeds the length of the array it will be appended.
* @param result OUT: the result buffer
* @return <code>buffer</code> (for chaining)
*/
-ReByteBuffer& ReStringList::join(const char* separator, ReByteBuffer& result) const{
+ReByteBuffer& ReStringList::join(const char* separator, ReByteBuffer& result,
+ bool append) const{
size_t theCount = count();
-
- result.setLength(0);
+ if (! append)
+ result.setLength(0);
size_t lengthSep = strlen(separator);
for (size_t ix = 0; ix < theCount; ix++){
}
return rc;
}
-/** @brief Returns the index of the first different string.
- *
- * Compares the internal array of strings with another instance
- *
- * @param toCompare the other instance which will be compared
- *
- * @return -1: the instances are equal. Otherwise: the index of the first different string
- *
- */
-int ReStringList::firstDiff(const ReStringList& toCompare) const{
- int rc = -1;
- int count1 = count();
- int count2 = toCompare.count();
- int maxIx = count1 > count2 ? count2 : count1;
- for (size_t ix = 0; rc == -1 && (int) ix < maxIx; ix++){
- if (sizeOf(ix) != toCompare.sizeOf(ix)
- || strcmp(strOf(ix), toCompare.strOf(ix)) != 0)
- rc = (int) ix;
- }
- if (rc == -1 && count1 != count2)
- rc = maxIx;
- return rc;
-}
-/** @brief Tests the equality with another instance.
- *
- * Compares the internal array of strings with another instance.
- * Two instances are equal when the number of strings are equal
- * and the n.th string is equal to the n.th string in the other instance.
- *
- * @param toCompare the other instance which will be compared
- *
- * @return true: the other instance is equal. false: Otherwise
- */
-bool ReStringList::equal(const ReStringList& toCompare) const{
- bool rc = count() == toCompare.count() && firstDiff(toCompare) == -1;
- return rc;
-}
Index indexOf(const char* toFind, bool ignoreCase = false,
Index start = 0) const;
void insert(Index index, const char* source, Tag tag = 0);
- ReByteBuffer& join(const char* separator, ReByteBuffer& result) const;
+ ReByteBuffer& join(const char* separator, ReByteBuffer& result, bool append = false) const;
Index nextStartingWith(Index index, const char* prefix,
bool ignoreCase = false);
bool readFromFile(const char* filename, bool cutNewline = true);
checkEqu("4", list.strOf(3));
checkEqu("", list.strOf(4));
checkEqu("99", list.strOf(5));
- ReByteBuffer value;
+ ReByteBuffer value("x");
list.join(";", value);
checkEqu(str, value.str());
- list.split("1\r\n2\n\r3", '\n');
- checkEqu(3U, list.count());
- checkEqu("1", list.strOf(0));
- checkEqu("2", list.strOf(1));
- checkEqu("3", list.strOf(2));
-
- list.split("xyz\tXYZ", '\t', true);
- checkEqu(5U, list.count());
- checkEqu("1", list.strOf(0));
- checkEqu("2", list.strOf(1));
- checkEqu("3", list.strOf(2));
- checkEqu("xyz", list.strOf(3));
- checkEqu("XYZ", list.strOf(4));
-
-
+ list.split("1\n2", '\n');
+ value.set("xxx", 3);
+ list.join(";", value, true);
+ checkEqu("xxx1;2", value.str());
}
void testFile(){
if (true){
ReTraverser traverser(m_base.str());
RePatternList patterns;
// exclude */cache/*
- ReByteBuffer buffer(";*;-*");
- buffer.append(OS_SEPARATOR).append("cache")
- .append(OS_SEPARATOR);
+ ReByteBuffer buffer(";*;-*/cache");
patterns.set(buffer.str());
traverser.setDirPattern(&patterns);
int level = 0;
checkOneFile("dir1_2_1", "dir1_2", hash);
checkOneFile("dir1_1", "dir1", hash);
checkOneFile("dir1_2", "dir1", hash);
- checkOneFile("dir1", m_base.str(), hash);
checkF(hash.get("cache.txt", buffer));
}
void testDirStatistic(){
ReByteBuffer buffer;
ReByteBuffer expected;
log(false, list.join("\n", buffer).str());
- checkEqu(3u, list.count());
+ checkEqu(4u, list.count());
// "1 t:\temp\winfried\2\retestunit\dir1\n"
buffer.set(list.strOf(0), list.strLengthOf(0));
checkT(buffer.startsWith("1\t"));
checkT(buffer.endsWith(expected.str()));
buffer.set(list.strOf(1), list.strLengthOf(1));
- checkT(buffer.startsWith(" 0.000008 MB 1 0\t"));
+ checkT(buffer.startsWith(" 0.000054 MB 2 3\t"));
expected.set(m_base.str(), m_base.length()).append("dir2", -1)
.append(OS_SEPARATOR);
checkT(buffer.endsWith(expected.str()));
rootList.append(item.str(), 0);
}
}
- if (rootList.count() > 0)
+ if (rootList.count() > 0){
list.append(rootList);
+ }
item.set(buffer.str(), 1);
- list.join(item.str(), buffer);
+ buffer.set(item);
+ list.join(item.str(), buffer, true);
}
/**
* Sets the standard filter options given by the program arguments.
}
return rc;
}
+
+/**
+ * Writes the content to a stream.
+ *
+ * @param fp target file pointer
+ * @param prefix NULL or a introduction
+ */
+void ReSimpleMatcher::dump(FILE* fp, const char* prefix) const{
+ ReByteBuffer buffer;
+ if (prefix != NULL)
+ fprintf(fp, "%s\n", prefix);
+ fprintf(fp, "pattern: %s token (%d): %s\n", m_pattern.str(),
+ m_tokens.count(), m_tokens.join(" ", buffer).str());
+}
+
/**
* Tests whether a name matches the pattern stored in the instance.
*
rc = ! rc;
return rc;
}
+/**
+ * Appends the status data of the instance onto the buffer.
+ *
+ * @param buffer OUT: the space for the data report
+ * @param prefix NULL or a prefix of the output
+ * @return <code>buffer.str()</code> (for chaining)
+ */
+const char* ReSimpleMatcher::status(ReByteBuffer& buffer, const char* prefix) const{
+ if (prefix != NULL)
+ buffer.append(prefix);
+ m_pattern.status(buffer, "pattern: ");
+ m_pattern.status(buffer, "tokens : ");
+ return buffer.str();
+}
/**
* Constructor.
delete[] m_patterns;
m_patterns = NULL;
}
+
+/**
+ * Writes the content to a stream.
+ *
+ * @param fp target file pointer
+ * @param prefix NULL or a introduction
+ */
+void RePatternList::dump(FILE* fp, const char* prefix) const{
+ ReByteBuffer buffer;
+ if (prefix != NULL)
+ fprintf(fp, "%s\n", prefix);
+ for (int ix = 0; ix < m_count; ix++){
+ fprintf(fp, "%d: ", ix);
+ m_patterns[ix]->dump(fp, NULL);
+ }
+}
+
/**
* Tests whether a name matches at least one of the patterns.
*
m_patterns[ix]->setIgnoreCase(ignoreCase);
return isNotPattern ? index: index + 1;
}
+
+/**
+ * Appends the status data of the instance onto the buffer.
+ *
+ * @param buffer OUT: the space for the data report
+ * @param prefix NULL or a prefix of the output
+ * @return <code>buffer.str()</code> (for chaining)
+ */
+const char* RePatternList::status(ReByteBuffer& buffer, const char* prefix) const{
+ if (prefix != NULL)
+ buffer.append(prefix);
+ for (int ix = 0; ix < m_count; ix++){
+ buffer.appendInt(ix).append(": ", 2);
+ m_patterns[ix]->status(buffer, NULL);
+ }
+ return buffer.str();
+}
virtual ~ReSimpleMatcher();
public:
virtual bool compile(const char* pattern);
+ void dump(FILE* fp, const char* prefix) const;
virtual bool match(const ReByteBuffer& toTest, ReHit* hit = NULL) const;
virtual bool search(const ReByteBuffer& toTest, ReHit* hit = NULL,
bool greedy = false) const;
+ const char* status(ReByteBuffer& buffer, const char* prefix) const;
protected:
bool searchTokens(const ReByteBuffer& toTest, int from, int to,
ReHit* hit, bool greedy) const;
return m_count;
}
void destroy();
+ void dump(FILE* fp, const char* prefix) const;
bool match(const ReByteBuffer& name);
/** @brief Tests whether a string matches the patterns.
* @param name the string to Test
const char* patternString() const
{ return m_patternString.str(); }
void set(const char* patterns, bool ignoreCase = false,
- const char* separator = NULL, const char* notPrefix = "-");
+ const char* separator = NULL, const char* notPrefix = "-");
+ const char* status(ReByteBuffer& buffer, const char* prefix) const;
private:
int setOne(int index, const char* pattern, size_t patternLength,
bool ignoreCase, const ReByteBuffer& notPrefix);