+ Move beautifyInteger() to stringTools.[h|cpp]

This commit is contained in:
kelson42 2012-04-28 16:16:54 +00:00
parent f48df4a960
commit 4dd4d510c9
4 changed files with 23 additions and 20 deletions

View File

@ -21,20 +21,6 @@
namespace kiwix { 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 */ /* Constructor */
Searcher::Searcher() : Searcher::Searcher() :
searchPattern(""), searchPattern(""),
@ -173,10 +159,10 @@ namespace kiwix {
result["snippet"] = this->resultOffset->snippet; result["snippet"] = this->resultOffset->snippet;
if (this->resultOffset->size >= 0) if (this->resultOffset->size >= 0)
result["size"] = this->beautifyInteger(this->resultOffset->size); result["size"] = ::beautifyInteger(this->resultOffset->size);
if (this->resultOffset->wordCount >= 0) if (this->resultOffset->wordCount >= 0)
result["wordCount"] = this->beautifyInteger(this->resultOffset->wordCount); result["wordCount"] = ::beautifyInteger(this->resultOffset->wordCount);
resultsCDT.PushBack(result); resultsCDT.PushBack(result);
this->resultOffset++; this->resultOffset++;
@ -208,7 +194,7 @@ namespace kiwix {
} }
oData["pages"] = pagesCDT; oData["pages"] = pagesCDT;
oData["count"] = this->beautifyInteger(this->estimatedResultCount); oData["count"] = ::beautifyInteger(this->estimatedResultCount);
oData["searchPattern"] = this->searchPattern; oData["searchPattern"] = this->searchPattern;
oData["resultStart"] = this->resultStart + 1; oData["resultStart"] = this->resultStart + 1;
oData["resultEnd"] = (this->resultEnd > this->estimatedResultCount ? this->estimatedResultCount : this->resultEnd); oData["resultEnd"] = (this->resultEnd > this->estimatedResultCount ? this->estimatedResultCount : this->resultEnd);

View File

@ -24,15 +24,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <iostream>
#include <vector> #include <vector>
#include <fstream>
#include <sstream>
#include <locale> #include <locale>
#include <cctype> #include <cctype>
#include <vector> #include <vector>
#include <unaccent.h> #include <unaccent.h>
#include <resourceTools.h> #include <resourceTools.h>
#include <stringTools.h>
#include <CTPP2Parser.hpp> #include <CTPP2Parser.hpp>
#include <CTPP2FileSourceLoader.hpp> #include <CTPP2FileSourceLoader.hpp>

View File

@ -19,6 +19,22 @@
#include "stringTools.h" #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<std::string> split(const std::string & str, std::vector<std::string> split(const std::string & str,
const std::string & delims=" *-") const std::string & delims=" *-")
{ {

View File

@ -20,9 +20,12 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <string> #include <string>
#include <fstream>
#include <sstream>
using namespace std; using namespace std;
std::string beautifyInteger(const unsigned int number);
std::vector<std::string> split(const std::string&, const std::string&); std::vector<std::string> split(const std::string&, const std::string&);
std::vector<std::string> split(const char*, const char*); std::vector<std::string> split(const char*, const char*);
std::vector<std::string> split(const std::string&, const char*); std::vector<std::string> split(const std::string&, const char*);