ddc
Classes
ddcString.h File Reference
#include "ddcConfig.h"
#include "utf8xx.h"
#include <stdarg.h>
#include <stdio.h>
#include <string>
Include dependency graph for ddcString.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  StringTokenizer
 
class  StringSplitter
 

Functions

std::string escapeCString (const std::string &s)
 
std::string unescapeCString (const std::string &s)
 
std::string escapeJsonString (const std::string &s, bool assume_utf8=true, bool add_quotes=false)
 
std::string unescapeJsonString (const std::string &s)
 
std::string jsonStr (const std::string &s, bool assume_utf8=true, bool add_quotes=true)
 
std::string jsonStr (unsigned char b)
 
std::string jsonStr (char c)
 
template<class Container >
std::string jsonArray (const Container &values)
 
std::string escapeUrlString (const std::string &s)
 
std::string unescapeUrlString (const std::string &s)
 
std::string unescapeUtf8String (const std::string &s)
 
std::string escapeChars (const std::string &s, const std::string &chars)
 
std::string sqString (const std::string &s)
 
std::string reString (const std::string &re)
 
std::string escapeRegex (const std::string &re)
 
std::string Format (const char *format,...)
 
std::string vFormat (const char *format, va_list &args)
 
char * StrError (int ErrorNo)
 
std::string TrimSafe (const std::string &str)
 
bool TrimTruncate (std::string &str, size_t max)
 
void TrimTruncateV (std::string &str, size_t max, const char *label=NULL)
 
bool StringToBool (const std::string &s, bool onempty=true)
 
const char * BoolToString (bool b)
 

Function Documentation

◆ escapeCString()

std::string escapeCString ( const std::string &  s)

Encode C escapes into string; encodes byte-wise with escapes

References Format().

Referenced by NavHintCache::insert(), NavHintCache::lower_bound(), and CHighlightTags::ToString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unescapeCString()

std::string unescapeCString ( const std::string &  s)

Decode C escapes in string. Also supports json-style "\uXXXX" utf8-escapes

◆ escapeJsonString()

std::string escapeJsonString ( const std::string &  s,
bool  assume_utf8 = true,
bool  add_quotes = false 
)

Encode JSON escapes into string.

  • If assume_utf8 is true (default), leaves bytes with high-bit set alone; otherwise encodes them as escapes.
  • If add_quotes is true, the returned string will be wrapped in JSON-friendly double quotes ("")

References Format().

Referenced by jsonStr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unescapeJsonString()

std::string unescapeJsonString ( const std::string &  s)

Decode all JSON escapes from a string.

◆ jsonStr() [1/3]

std::string jsonStr ( const std::string &  s,
bool  assume_utf8 = true,
bool  add_quotes = true 
)
inline

wrapper for escapeJsonString

References escapeJsonString().

Referenced by jsonArray(), and jsonStr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ jsonStr() [2/3]

std::string jsonStr ( unsigned char  b)
inline

jsonStr(unsigned char) maps to unsigned int

◆ jsonStr() [3/3]

std::string jsonStr ( char  c)
inline

jsonStr(char) maps to single-character string

References jsonStr().

Here is the call graph for this function:

◆ jsonArray()

template<class Container >
std::string jsonArray ( const Container &  values)

◆ escapeUrlString()

std::string escapeUrlString ( const std::string &  s)

URL-encode the string s with XX escapes

Referenced by jsonArray().

Here is the caller graph for this function:

◆ unescapeUrlString()

std::string unescapeUrlString ( const std::string &  s)

Unescape URL-encoding XX of s

Referenced by jsonArray().

Here is the caller graph for this function:

◆ unescapeUtf8String()

std::string unescapeUtf8String ( const std::string &  s)

Decode escapes from a string to UTF-8

Referenced by jsonArray().

Here is the caller graph for this function:

◆ escapeChars()

std::string escapeChars ( const std::string &  s,
const std::string &  chars 
)

Escape selected characters chars in a string s

Referenced by jsonArray().

Here is the caller graph for this function:

◆ sqString()

std::string sqString ( const std::string &  s)

◆ reString()

std::string reString ( const std::string &  re)

quote a regex in slashes //

Referenced by jsonArray(), CQFHasFieldRegex::valueString(), and CQTokRegex::ValueString().

Here is the caller graph for this function:

◆ escapeRegex()

std::string escapeRegex ( const std::string &  re)

escape regex operators .*+?\ etc

References escapeChars().

Referenced by CQFHasFieldInfix::CQFHasFieldInfix(), CQFHasFieldPrefix::CQFHasFieldPrefix(), CQFHasFieldSuffix::CQFHasFieldSuffix(), and jsonArray().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Format()

std::string Format ( const char *  format,
  ... 
)

wrapper for vsnprintf() which returns a C++ string

References DDC_STATIC_BUFLEN.

Referenced by MorphoWizard::add_lemma(), CHitBorders::AddBreakByIndex(), CTabFormatIndexator::AddColumnMap(), CTempArticle::AddCortegeToVector(), ConcIndexatorInvoker::AddInputLoadIndexToMemoryLoadIndexWrapper(), AddMessage(), CIndexSetForQueryingStage::AddOneIndexItem(), CDDCBranchServer::AlignCorpusPath(), ConcIndexatorInvoker::BuildIndex(), ConcIndexatorInvoker::BuildIndexStart(), CGraphanDicts::BuildOborottos(), CConcSessionContext::CacheGet(), CConcSessionContext::CacheSet(), CDocumentIterator::CDocumentIterator(), MorphoWizard::check_paradigm(), CTempArticle::CheckCortegeVector(), CItemIndexForLoading::CheckOccurrences(), CHost::ClientError(), ddcMMap< CIndexItem >::close(), CHost::CloseListenSocket(), CloseSocketRef(), CQCountKeyExprBibl::Compile(), TxCab::compile(), CFreeBiblStringIndex::ConvertAndSaveToDiskAfterIndexing(), CQCount::countOptionsToString(), CQFRandomSort::CQFRandomSort(), CQFSizeSort::CQFSizeSort(), CQFSort::CQFSort(), CQueryNearNode::Create(), create_inet_socket(), create_unix_socket(), CConcIndexator::CreateAsUnion(), CHost::CreateListener(), CFreeBiblStringIndex::CreatePartitions(), CreatePartitionStorage(), CHost::CreateSocket(), CStringIndexSet::CreateSplitPartitions(), CFreeBiblStringIndex::CreateUnion(), CStringIndexSet::CreateUnionTokenStorages(), ddcLog(), CHitToSort::debugStr(), ddcObject::Descendants(), do_start(), CConcordance::DumpFileBibliography(), CConcordance::DumpIndex(), CMyTimeSpanHolder::EndTimer(), ddcMapFile< DWORD, DWORD >::ensureMap(), ddcStringEnum< OffT_ >::ensureVec(), ddcCorpusList< OffT_ >::ensureVec(), ddcVecFile< CIndexItem >::ensureVec(), escapeCString(), escapeJsonString(), CQCountKeyExpr::Evaluate(), TxMorph::expand(), TxCab::expand(), FileAppend(), FileAppendPartial(), ConcIndexatorInvoker::FinalizeIndex(), CConcXml::FinalSaveBibliography(), CFormInfo::FormatAsInPlmLine(), CBiblIndex::FreeBiblMapToJson(), GenerateCountString(), CConcSession::GenerateCountStrings(), CConcSession::GenerateOneHitString(), CConcSession::GenerateOneHitStringJson(), CMorphDictBuilder::GenPredictIdx(), CConcSession::GetAllHits(), CHitBorders::GetBorderIndicesString(), CHitBorders::CBreakCollection::GetBreakFileName(), CConcSession::GetContext(), CConcSession::GetContextJson(), CConcSession::GetCountIds(), GetCWBFormattedStringRecursive(), CFreeBiblIndex::GetDescriptionStr(), CDDCBranchServer::GetFirstHitsFromCorpora(), CBiblIndex::GetFreeBibiAttributesDescr(), CDDCBranchServer::GetHitContexts(), CConcSession::GetHitIds(), CConcSession::GetHits(), CDDCBranchServer::GetHitStringsFromOneCorpus(), CConcordance::GetHtmlReference(), CStringIndexator::GetIndicesString(), CConcordance::GetIndicesToShowStr(), GetLogLevel(), CHost::GetRequest(), CFreeBiblIndex::GetStringValue(), CDDCBranchServer::GetSubcorpusJsonStrings(), CBiblIndex::GetTextAreaElements(), CBiblIndex::GetTextAreasDescr(), GetTextFromXMLRecursive(), TRoss::GetUnitTextHeader(), GetWordForms(), CDDCLeafServer::handle__clear_cache(), CDDCBranchServer::handle__clear_cache(), CDDCLeafServer::handle__expand_terms(), CDDCBranchServer::handle__expand_terms(), CDDCLeafServer::handle__get_first_hits(), CDDCBranchServer::handle__get_first_hits(), CDDCLeafServer::handle__get_hit_strings(), CDDCBranchServer::handle__get_hit_strings(), CDDCLeafServer::handle__info(), CDDCBranchServer::handle__nodes(), CDDCLeafServer::handle__reload(), CDDCBranchServer::handle__reload(), CDDCLeafServer::handle__run_query(), CDDCBranchServer::handle__run_query(), CDDCLeafServer::handle__status(), CDDCBranchServer::handle__status(), CHost::HandleClientConnection(), CDDCServer::HandleClientConnection(), CHost::HandleSocketError(), CDictionary::ImportFromText(), ConcIndexatorInvoker::IndexFile(), ConcIndexatorInvoker::IndexFiles(), CConcIndexator::IndexOneTableTextArea(), CStringIndexator::IndexOneToken(), CTabFormatIndexator::IndexTabFormat(), CConcIndexator::IndexTextOrHtmlFile(), CStringIndexator::IndexTokenFixLongColumns(), CConcIndexator::InitGraphan(), InitMorphologySystem(), CConcSession::InitSortByContext(), CConcSession::InitSortByRank(), NavHintCache::insert(), TRoss::InsertDomItem(), jsonArray(), CQueryOptions::jsonData(), CQCountKeyExprDateSlice::jsonData(), CQCountKeyExprToken::jsonData(), CQFContextSort::jsonData(), CQWith::jsonData(), CQCount::jsonData(), CQToken::jsonData(), CQKeys::jsonData(), CQFPrune::jsonData(), CQNear::jsonData(), CQTokAnchor::jsonValue(), ListenerThread(), CMorphDict::Load(), CMorphAutomat::Load(), CBiblIndex::LoadBibl(), LoadDDCServer(), CDDCServerOptions::LoadFile(), CConcIndexator::LoadFileIntoGraphan(), CDDCLeafServer::LoadHolder(), CIndexSetForQueryingStage::LoadIndexSet(), CDDCServerOptions::LoadLines(), LoadLocalCorpora(), CConcordance::LoadMaskedFiles(), TRoss::LoadOnlyConstants(), CConcordance::LoadOptionsFromFile(), CConcordance::LoadOptionsFromString(), CConcordance::LoadProject(), CConcordance::LoadSourceFilesAndOptions(), CGraphmatFile::LoadStringToGraphan(), CConcXml::LoadXmlAndReadBibliography(), CConcIndexator::LoadXmlFile(), NavHintCache::lower_bound(), MakeDirP(), CTempArticle::MarkUp(), CQToken::MatchIdString(), ddcMMap< CIndexItem >::open(), ddcStringEnum< OffT_ >::open(), ddcCorpusList< OffT_ >::open(), ddcRecFile::open(), ddcFileOrMMap::Open(), ddcStringEnum< OffT_ >::openCompat(), ddcCorpusList< OffT_ >::openCompat(), ConcIndexatorInvoker::PrintProgress(), CTabFormatIndexator::ProcessMetaField(), CDictionary::ProcessOneArticle(), CDDCServer::ProcessSocketString(), CFreeBiblIndex::ReadFromDisk(), CDumpParadigm::ReadFromFile(), CConcXml::ReadMorphXmlFileIntoGraTable(), MorphoWizard::ReadNextParadigmFromFile(), CDDCBranchServer::ReadSelectedHosts(), MorphoWizard::ReadSessions(), CSourceFileHolder::ReadSourceFileList(), CDocumentIterator::ReadTabFormatDocument(), ReadTabFormatDocumentName(), ReadVectorInner(), ReadXmlField(), CFreeBiblStringIndex::RegisterBiblStringItemId(), CHitBorders::RegisterBorderIndices(), CBiblIndex::RegisterFreeBiblAttributes(), CStringIndexator::RegisterIndexAlias(), CStringIndexator::RegisterIndexAliases(), CConcordance::RegisterIndicesToShow(), CConcIndexator::RollbackIndexOneFile(), CIndexSetForLoadingStage::RollbackLoadIndex(), CDDCServerThread::run(), CDDCBranchServer::RunDistributed(), CDDCBranchServer::RunGetFirstHits(), CHost::RunThread(), CBibliography::Sanitize(), SanitizeBiblString(), CMorphDict::Save(), CMorphAutomat::Save(), ddcVecFile< CIndexItem >::save(), MorphoWizard::save_mrd(), ConcIndexatorInvoker::SaveLoadIndexToDisk(), CConcSession::SaveOccurrences(), SaveOnePartOfUnionTokenStorage(), CConcordance::SaveOptionsToString(), send_buffer(), CDDCBranchServer::SendGetHitStringsRequest(), CHost::SendResponse(), CDDCServerOptions::Set(), CConcXml::SetFreeBiblByName(), CDDCServer::SetOptions(), CDDCBranchServer::SetOptions(), MorphoWizard::show_differences_in_two_paradigms(), CConcSession::ShowBibliographyForTable(), CConcSession::ShowBibliographyForTextOrHtml(), CDDCLeafServer::Shutdown(), CDDCServer::Shutdown(), CDDCBranchServer::Shutdown(), CConcSession::SimpleQuery(), SocketPeer(), CConcSession::SortKeyLB(), CConcXml::SplitBibliography(), CConcIndexator::SplitProject(), CDDCServerThreadPool::start(), CHitBorders::StartIndexing(), tar_get_next_file(), tar_header::th_get_pathname(), NavHintKey::toJson(), NavHint::toJson(), NavHintCache::toJson(), DDCTimeAvg::toJsonArray(), DDCTimeAvg::toJsonMap(), CHighlightTags::ToString(), CAccentModel::ToString(), NavHintKey::toString(), CDDCServerOptions::toString(), CMorphSession::ToString(), CSocketAddr::toString(), CQueryOptions::toString(), CQCountKeyExprDateSlice::toString(), CSelectedHosts::toString(), CRunQueryData::toString(), CQCountKeyExprToken::toString(), CQFContextSort::toString(), CQWith::toString(), CQFPrune::toString(), CQKeys::toString(), CQNear::toString(), CQSeq::toString(), TrimTruncateV(), CConcXml::UnionBibliographies(), CStringIndexSet::UnionIndexSets(), CDDCBranchServer::UpdateNavCache(), CQTokAnchor::ValueString(), CConcSession::WorkerClone(), CFreeBiblStringIndex::WriteBiblStringItems(), and CIndexSetForQueryingStage::WritePeriodsDivision().

◆ vFormat()

std::string vFormat ( const char *  format,
va_list &  args 
)

wrapper for vsnprintf(), va_list version

References DDC_STATIC_BUFLEN.

Referenced by EchoOption(), and jsonArray().

Here is the caller graph for this function:

◆ StrError()

char* StrError ( int  ErrorNo)

wrapper for strerror_r() if available, otherwise wraps strerror()

Referenced by create_inet_socket(), create_unix_socket(), CreateWaitFile(), do_start(), do_stop(), CConcordance::DumpIndex(), jsonArray(), CDDCServerOptions::LoadFile(), read_pid_from_lock_file(), receive_buffer(), CHost::RunThread(), and send_buffer().

Here is the caller graph for this function:

◆ TrimSafe()

std::string TrimSafe ( const std::string &  str)

constructive variant of Trim() from utilit.(h|cpp): trims leading and trailing whitespace from argument, returns new trimmed string

Referenced by StringSplitter::operator++(), and CDDCServerOptions::Set().

Here is the caller graph for this function:

◆ TrimTruncate()

bool TrimTruncate ( std::string &  str,
size_t  max 
)
inline

truncate string str to maxLen bytes if str.size() > max

Returns
true iff string was actually truncated

References BoolToString(), StringToBool(), and TrimTruncateV().

Referenced by CFreeBiblStringIndex::RegisterBiblStringItemId(), CBibliography::Sanitize(), SanitizeBiblString(), and TrimTruncateV().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TrimTruncateV()

void TrimTruncateV ( std::string &  str,
size_t  max,
const char *  label = NULL 
)

verbose auto-truncation: logs a warning "LABEL ILABEL truncated to max=MAX bytes" on truncation

References ddcLogWarn, Format(), and TrimTruncate().

Referenced by TrimTruncate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StringToBool()

bool StringToBool ( const std::string &  s,
bool  onempty = true 
)

option-parsing utility for boolean options

References stolower().

Referenced by CConcordance::LoadOptionsFromString(), CDDCServerOptions::Set(), and TrimTruncate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BoolToString()

const char* BoolToString ( bool  b)

boolean value reporting for options

Referenced by CConcordance::LoadOptionsFromString(), CDDCServerOptions::toString(), and TrimTruncate().

Here is the caller graph for this function: