From 4dd4d510c96d31766636cc3c370f176fd86feeb3 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sat, 28 Apr 2012 16:16:54 +0000 Subject: [PATCH] + Move beautifyInteger() to stringTools.[h|cpp] --- src/common/kiwix/searcher.cpp | 20 +++----------------- src/common/kiwix/searcher.h | 4 +--- src/common/stringTools.cpp | 16 ++++++++++++++++ src/common/stringTools.h | 3 +++ 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/common/kiwix/searcher.cpp b/src/common/kiwix/searcher.cpp index 8607aae4f..8bc300fc3 100644 --- a/src/common/kiwix/searcher.cpp +++ b/src/common/kiwix/searcher.cpp @@ -21,20 +21,6 @@ namespace kiwix { - /* Count word */ - std::string Searcher::beautifyInteger(const unsigned int number) { - stringstream numberStream; - numberStream << number; - std::string numberString = numberStream.str(); - - signed int offset = numberString.size() - 3; - while (offset > 0) { - numberString.insert(offset, ","); - offset -= 3; - } - return numberString; - } - /* Constructor */ Searcher::Searcher() : searchPattern(""), @@ -173,10 +159,10 @@ namespace kiwix { result["snippet"] = this->resultOffset->snippet; if (this->resultOffset->size >= 0) - result["size"] = this->beautifyInteger(this->resultOffset->size); + result["size"] = ::beautifyInteger(this->resultOffset->size); if (this->resultOffset->wordCount >= 0) - result["wordCount"] = this->beautifyInteger(this->resultOffset->wordCount); + result["wordCount"] = ::beautifyInteger(this->resultOffset->wordCount); resultsCDT.PushBack(result); this->resultOffset++; @@ -208,7 +194,7 @@ namespace kiwix { } oData["pages"] = pagesCDT; - oData["count"] = this->beautifyInteger(this->estimatedResultCount); + oData["count"] = ::beautifyInteger(this->estimatedResultCount); oData["searchPattern"] = this->searchPattern; oData["resultStart"] = this->resultStart + 1; oData["resultEnd"] = (this->resultEnd > this->estimatedResultCount ? this->estimatedResultCount : this->resultEnd); diff --git a/src/common/kiwix/searcher.h b/src/common/kiwix/searcher.h index 6b5cfb5b2..37cc8e901 100644 --- a/src/common/kiwix/searcher.h +++ b/src/common/kiwix/searcher.h @@ -24,15 +24,13 @@ #include #include #include -#include #include -#include -#include #include #include #include #include #include +#include #include #include diff --git a/src/common/stringTools.cpp b/src/common/stringTools.cpp index a883a7d40..217038670 100644 --- a/src/common/stringTools.cpp +++ b/src/common/stringTools.cpp @@ -19,6 +19,22 @@ #include "stringTools.h" +/* Prepare integer for display */ +std::string beautifyInteger(const unsigned int number) { + stringstream numberStream; + numberStream << number; + std::string numberString = numberStream.str(); + + signed int offset = numberString.size() - 3; + while (offset > 0) { + numberString.insert(offset, ","); + offset -= 3; + } + + return numberString; +} + +/* Split string in a token array */ std::vector split(const std::string & str, const std::string & delims=" *-") { diff --git a/src/common/stringTools.h b/src/common/stringTools.h index 081955ef0..260a8cd9e 100644 --- a/src/common/stringTools.h +++ b/src/common/stringTools.h @@ -20,9 +20,12 @@ #include #include #include +#include +#include using namespace std; +std::string beautifyInteger(const unsigned int number); std::vector split(const std::string&, const std::string&); std::vector split(const char*, const char*); std::vector split(const std::string&, const char*);