strusBase  0.17
Namespaces | Classes | Typedefs | Enumerations | Functions
strus Namespace Reference

Wrapper to structures needed for atomic counters. More...

Namespaces

 platform
 
 utils
 

Classes

class  atomic
 
class  AtomicCounter
 
class  AtomicFlag
 
struct  BitOperations
 
struct  bitset_hi_bitmask
 
struct  bitset_hi_bitmask< 0 >
 
class  bitset
 
class  DataRecordFile
 Basic portable file type for collections of equal sized records with random access. More...
 
class  dynamic_bitset
 
struct  enable_if
 
class  ByteOrder
 
class  ByteOrder< uint8_t >
 
class  ByteOrder< int8_t >
 
class  ByteOrder< uint16_t >
 
class  ByteOrder< int16_t >
 
class  ByteOrder< uint32_t >
 
class  ByteOrder< int32_t >
 
class  ByteOrder< uint64_t >
 
class  ByteOrder< int64_t >
 
class  ByteOrder< float >
 
class  ByteOrder< double >
 
class  InputStream
 Abstraction of input stream. More...
 
class  local_ptr
 
class  LocalErrorBuffer
 Error buffer implementation for a context transforming the error message into an exceptions at the end of its scope. More...
 
struct  numstring_conv
 Inlined version of string to number conversion functions throwing an exception instead of setting an error code on failure. More...
 
class  PeriodicTimerEvent
 Periodic timer event. More...
 
class  ProgramLexem
 Class for a lexem in a domain specific programming language with the following properties. More...
 
class  ProgramLexer
 Class for a lexer used for implementing domain specific languages of strus. More...
 
class  ProgramOptions
 Program options parser. More...
 
class  PseudoRandom
 Pseudo random generator. Fast generator for series of pseudo random numbers where the security is not an issue and the quality of the distribution has not to be guaranteed. More...
 
class  RegexSearch
 Class to search for a regular expression. More...
 
class  RegexSubst
 Class to replace a regular expression by a string with sub-matches as substitute. More...
 
class  shared_ptr
 
struct  string_conv
 Inlined version of string conversion functions throwing an exception instead of setting an error code on failure. More...
 
class  BlockAllocator
 
class  SymbolTable
 Map of strings to indices not freed till end of table life time. More...
 
class  ThreadId
 
struct  is_arithmetic
 
struct  is_same
 
struct  DefaultDeleter
 
class  unique_ptr
 
class  unordered_map
 
class  DebugTraceMessage
 One item of a debug trace. More...
 
class  DebugTraceContextInterface
 Interface for reporting debug trace messages in a uniform way. More...
 
class  DebugTraceInterface
 Managing interface for reporting debug trace messages in a uniform way. More...
 
class  ErrorBufferInterface
 Interface for reporting and catching errors in modules. More...
 
class  FileLocatorInterface
 Interface for locating resource files and working directory. More...
 
class  NumericVariant
 Atomic type that can hold numeric values of different type. More...
 
class  Reference
 Shared pointer template with non thread-safe reference counting. More...
 

Typedefs

typedef uint32_t float_net_t
 
typedef uint64_t double_net_t
 
typedef boost::mutex mutex
 
typedef boost::recursive_mutex recursive_mutex
 
typedef boost::mutex::scoped_lock scoped_lock
 
typedef boost::unique_lock
< boost::mutex > 
unique_lock
 
typedef boost::unique_lock
< boost::recursive_mutex > 
recursive_unique_lock
 
typedef boost::condition_variable condition_variable
 
typedef boost::thread thread
 

Enumerations

enum  NumParseError {
  NumParseOk = 0x0, NumParseErrNoMem = 0x1, NumParseErrConversion = 0x2, NumParseErrOutOfRange = 0x3,
  NumParseErrInvalidArg = 0x4
}
 
enum  StringConvError { StringConvOk = 0x0, StringConvErrNoMem = 0x1, StringConvErrConversion = 0x2 }
 
enum  {
  B11111111 =0xFF, B01111111 =0x7F, B00111111 =0x3F, B00011111 =0x1F,
  B00001111 =0x0F, B00000111 =0x07, B00000011 =0x03, B00000001 =0x01,
  B00000000 =0x00, B10000000 =0x80, B11000000 =0xC0, B11100000 =0xE0,
  B11110000 =0xF0, B11111000 =0xF8, B11111100 =0xFC, B11111110 =0xFE,
  B11011111 =B11000000|B00011111, B11101111 =B11100000|B00001111, B11110111 =B11110000|B00000111, B11111011 =B11111000|B00000011,
  B11111101 =B11111100|B00000001
}
 
enum  ErrorCode {
  ErrorCodeUnknown =0, ErrorCodeErrno =201, ErrorCodeOutOfMem =202, ErrorCodeDataCorruption =203,
  ErrorCodeMutexLockFailed =214, ErrorCodeLogicError =215, ErrorCodeUncaughtException =216, ErrorCodeAvailability =220,
  ErrorCodeNotAllowed =221, ErrorCodeProtocolError =222, ErrorCodePlatformIncompatibility =223, ErrorCodePlatformRequirements =224,
  ErrorCodeSyntax =228, ErrorCodeNotFound =229, ErrorCodeIOError =230, ErrorCodeVersionMismatch =231,
  ErrorCodeInvalidArgument =232, ErrorCodeInvalidRegex =233, ErrorCodeInvalidOperation =234, ErrorCodeInvalidFilePath =235,
  ErrorCodeLoadModuleFailed =236, ErrorCodeNotImplemented =237, ErrorCodeIncompleteInitialization =238, ErrorCodeIncompleteDefinition =239,
  ErrorCodeIncompleteConfiguration =240, ErrorCodeBindingLanguageError =251, ErrorCodeUnknownIdentifier =252, ErrorCodeOperationOrder =253,
  ErrorCodeValueOutOfRange =254, ErrorCodeMaxLimitReached =255, ErrorCodeBufferOverflow =256, ErrorCodeMaxNofItemsExceeded =257,
  ErrorCodeMaxRecursionDepht =258, ErrorCodeRuntimeError =259, ErrorCodeIncompleteRequest =265, ErrorCodeIncompleteResult =266,
  ErrorCodeUnexpectedEof =271, ErrorCodeHiddenError =272, ErrorCodeInputFormat =281, ErrorCodeEncoding =282,
  ErrorCodeRequestResolveError =283, ErrorCodeNotAcceptable =284
}
 Application error codes beyond errno (>= 200) More...
 

Functions

void printIndentMultilineString (std::ostream &out, std::size_t indentsize, const char *descr, ErrorBufferInterface *errorhnd)
 Print a multiline string with indentiation. More...
 
bool extractStringFromConfigString (std::string &val, std::string &config, const char *key, ErrorBufferInterface *errorhnd)
 
bool extractStringArrayFromConfigString (std::vector< std::string > &val, std::string &config, const char *key, char separator, ErrorBufferInterface *errorhnd)
 
bool extractBooleanFromConfigString (bool &val, std::string &config, const char *key, ErrorBufferInterface *errorhnd)
 
bool extractUIntFromConfigString (unsigned int &val, std::string &config, const char *key, ErrorBufferInterface *errorhnd)
 
bool extractFloatFromConfigString (double &val, std::string &config, const char *key, ErrorBufferInterface *errorhnd)
 
void removeKeysFromConfigString (std::string &config, const char **keys, ErrorBufferInterface *errorhnd)
 
bool addConfigStringItem (std::string &config, const std::string &key, const std::string &value, ErrorBufferInterface *errorhnd)
 
std::vector< std::pair
< std::string, std::string > > 
getAssignmentListItems (const std::string &config, ErrorBufferInterface *errorhnd)
 
std::vector< std::pair
< std::string, std::string > > 
getConfigStringItems (const std::string &config, ErrorBufferInterface *errorhnd)
 
std::vector< std::pair
< std::string, std::string > > 
getSubConfigStringItems (const std::string &configelem, ErrorBufferInterface *errorhnd)
 
int getenv (const std::string &var, std::string &output)
 Read an environment variable value as string. More...
 
int getenv_list (const std::string &var, char sep, std::vector< std::string > &output)
 Read an environment variable value as array of strings, separated by a separator character. More...
 
char separatorPathList ()
 Separator character used for separating file paths in environment variables. More...
 
int execv_tostring (const char *filename, const char *const argv[], std::string &output)
 Execution of a command appending the output to a string. More...
 
int execve_tostring (const char *filename, const char *const argv[], const std::map< std::string, std::string > &env, std::string &output)
 Execution of a command with some environment variables set, appending the output to a string. More...
 
int readFileSize (const std::string &filename, std::size_t &size)
 Evaluate the size of a file in bytes. More...
 
int readFile (const std::string &filename, std::string &res)
 Reads the complete content of a file to a string. More...
 
int readStdin (std::string &res)
 Reads the complete input of stdin to a string. More...
 
int writeFile (const std::string &filename, const std::string &content)
 Writes a string to a file creating the file if it does not exist. More...
 
int appendFile (const std::string &filename, const std::string &content)
 Appends a string to a file creating the file if it does not exist. More...
 
int removeFile (const std::string &filename, bool fail_ifnofexist=false)
 Removes a file. More...
 
int removeDir (const std::string &dirname, bool fail_ifnofexist=false)
 Removes an empty directory. More...
 
int removeDirRecursive (const std::string &dirname, bool fail_ifnofexist=false)
 Removes a directory with all its contents. More...
 
int renameFile (const std::string &old_filename, const std::string &new_filename)
 Moves (renames) a file. More...
 
int createDir (const std::string &dirname, bool fail_ifexist=true)
 Creates a directory if it does not exist yet. More...
 
int mkdirp (const std::string &dirname)
 Creates a directory path (mkdir -p) More...
 
int changeDir (const std::string &dirname)
 Change current directory of the process. More...
 
int readDirFiles (const std::string &path, const std::string &ext, std::vector< std::string > &res)
 Reads all file names matching to the extension ext of a directory to an array of strings. More...
 
int readDirSubDirs (const std::string &path, std::vector< std::string > &res)
 Reads all subdirectories of a directory to an array of strings. More...
 
int readDirItems (const std::string &path, std::vector< std::string > &res)
 Reads all items (directory or file) of a directory to an array of strings. More...
 
int expandFilePattern (const std::string &pathPattern, std::vector< std::string > &res)
 Get all items matching a file path pattern (with '?' and '*' as substitutes) More...
 
bool isFile (const std::string &path)
 Check if a file system path points to a file. More...
 
bool isDir (const std::string &path)
 Check if a file system path points to a directory. More...
 
bool isRelativePath (const std::string &path)
 Check if a file system path is a path starting with a name and not with a directive referencing the current path './' or the file system root '/'. More...
 
bool isAbsolutePath (const std::string &path)
 Check if a file system path is a path starting the file system root '/'. More...
 
bool isExplicitPath (const std::string &path)
 Check if a file path is explicit (relative path or absolute path) More...
 
bool isTextFile (const std::string &path)
 Check if a file system path points to a file with text content (not binary) More...
 
int getParentPath (const std::string &path, std::string &dest)
 Get the parent (containing) path of a file or directory. More...
 
int getAncestorPath (const std::string &path, int level, std::string &dest)
 Get an ancestor (containing) path of a file or directory. More...
 
int getFileName (const std::string &path, std::string &dest, bool withExtension=true)
 Get the file name without parent path of a file or directory. More...
 
int getFileExtension (const std::string &path, std::string &ext)
 Get the extension (including '.') of a file or directory. More...
 
char dirSeparator ()
 Get the OS path element separator. More...
 
bool hasUpdirReference (const std::string &path)
 Return true, if the path contains an upper directory reference '..'. More...
 
std::string joinFilePath (const std::string &parentpath, const std::string &childpath)
 Join two path with directory separator. More...
 
int resolveUpdirReferences (std::string &path)
 Resolve upper directory references in a path, e.g. replace "/home/john/../jack" by "/home/jack". More...
 
void aligned_free (void *ptr)
 
void * aligned_malloc (std::size_t size, std::size_t alignment)
 
const char * numstring_error (NumParseError errcode)
 Convert string conversion error code into an error message string. More...
 
std::runtime_error numstring_exception (NumParseError errcode)
 Convert string conversion error code into an exception. More...
 
double doubleFromString (const std::string &numstr, NumParseError &err)
 Parsing a double precision floating point number from an Ascii string. More...
 
double doubleFromString (const char *numstr, std::size_t numsize, NumParseError &err)
 Parsing a double precision floating point number from an Ascii string. More...
 
int64_t intFromString (const std::string &numstr, int64_t maxvalue, NumParseError &err)
 Parsing an integer number from an Ascii string. More...
 
int64_t intFromString (const char *numstr, std::size_t numsize, int64_t maxvalue, NumParseError &err)
 Parsing an integer number from an Ascii string. More...
 
uint64_t uintFromString (const std::string &numstr, uint64_t maxvalue, NumParseError &err)
 Parsing an unsigned integer number from an Ascii string. More...
 
uint64_t uintFromString (const char *numstr, std::size_t numsize, uint64_t maxvalue, NumParseError &err)
 Parsing an unsigned integer number from an Ascii string. More...
 
void sleep (int nofsecs)
 
std::runtime_error stringconv_exception (StringConvError errcode)
 Convert string conversion error code into an exception. More...
 
std::string tolower (const char *val, StringConvError &err)
 Convert ASCII letters in string to lowercase. More...
 
std::string tolower (const char *val, std::size_t size, StringConvError &err)
 Convert ASCII letters in string to lowercase. More...
 
std::string tolower (const std::string &val, StringConvError &err)
 Convert ASCII letters in string to lowercase. More...
 
std::string trim (const std::string &val, StringConvError &err)
 Trim trailing and heading whitespace and control characters. More...
 
std::string trim (const char *val, std::size_t size, StringConvError &err)
 Trim trailing and heading whitespace and control characters. More...
 
bool isEmptyString (const char *val, std::size_t size)
 Evaluate if a string is empty or contains only space characters. More...
 
bool isEmptyString (const std::string &val)
 Evaluate if a string is empty or contains only space characters. More...
 
bool caseInsensitiveEquals (const std::string &val1, const std::string &val2)
 Compare on Ascii letter caseinsensitive equality. More...
 
bool caseInsensitiveStartsWith (const std::string &val, const std::string &prefix)
 Test prefix on Ascii letter caseinsensitive equality. More...
 
bool stringStartsWith (const std::string &val, const std::string &prefix)
 Test prefix on equality. More...
 
std::string utf8clean (const std::string &name, StringConvError &err)
 Convert possibly broken UTF-8 to valid UTF-8. More...
 
std::string unescape (const std::string &val, StringConvError &err)
 Convert excaped control characters to their unescaped form (e.g. \n to
) More...
 
std::string string_format (const char *fmt, va_list ap)
 Get a string built from a format string and arguments. More...
 
std::string string_format (const char *fmt,...)
 Get a string built from a format string and arguments. More...
 
static bool utf8midchr (unsigned char ch)
 Return true, if the character passed as argument is a non start character of a multi byte encoded unicode character. More...
 
static const char * utf8prev (char const *end)
 Skip to the begin of an UTF-8 encoded character from a pointer into it. More...
 
static unsigned char utf8charlen (unsigned char ch)
 Get the lenght of an UTF-8 encoded character from its first byte. More...
 
int32_t utf8decode (const char *itr, unsigned int charsize)
 Decoding of a single UTF-8 character in a string. More...
 
std::size_t utf8encode (char *buf, int32_t chr)
 Encoding of a single UTF-8 character into a string buffer. More...
 
DebugTraceInterfacecreateDebugTrace_standard (std::size_t maxNofThreads_)
 Create an debug trace interface. More...
 
bool dumpDebugTrace (DebugTraceInterface *debugTrace, const char *filename)
 Dump the trace content in a convenient form to a file specified. More...
 
ErrorBufferInterfacecreateErrorBuffer_standard (FILE *logfilehandle, std::size_t maxNofThreads_, DebugTraceInterface *debugTrace)
 Create an error buffer interface. More...
 
int errorCodeFromMessage (char const *&msgitr)
 Get the next error code in an error message printed by the standard error buffer implementation provided here. More...
 
void removeErrorCodesFromMessage (char *msg)
 Remove all error codes in an error message printed by the standard error buffer implementation provided here. More...
 
const char * errorCodeToString (int errcode)
 Get the error message as string. More...
 
FileLocatorInterfacecreateFileLocator_std (ErrorBufferInterface *errorhnd)
 Create a file locator interface. More...
 

Detailed Description

Wrapper to structures needed for atomic counters.

Wrapper to hash table implementation.

Wrapper to std or boost type traits.

Wrapper to structures needed for multithreading.

Map of strings to indices not freed till end of table life time.

Get a string built by a format string.

Some string conversion functions.

Sleep function (mainly for testing)

Definition of strus::shared_ptr.

Regular expression matching.

Fast generator for series of pseudo random numbers where the security is not an issue and the quality of the distribution has not to be guaranteed.

Class for a lexer used for implementing domain specific languages of strus.

Periodic timer event.

Some functions to parse a number from a string and to print a number to a string.

Some malloc wrappers.

strus toplevel namespace

Definition of strus::local_ptr a substitute for std::auto_ptr used in a local scope without copying or std::unique_ptr for C++ >= 11.

Basic portable file read/write and related filesystem functions.

Execution of a command appending results to string.

Accessing environment variables.

Wrapper to std::enable_if/boost::enable_if_c.

Wrapper to dynamic bitset implementation.

Basic portable file type for collections of equal sized records with random access.

Method to calculate CRC32 values that can be used for hashing or checksums in messages.

Some functions to parse a configuration string (e.g. strus storage configuration)

Some helpers for command line processing.

Bitset implementation.

PF:HACK: Bad solution, need probing of atomic as C++ feature as for regex

Note
We do not use STL <bitset> because we need insert and remove and an iterator, besides toggling bits

PF:HACK: Bad solution, need probing of dynamic_bitset as C++ feature as for regex

PF:HACK: Bad solution, need probing of enable_if as C++ feature as for regex

Note
Mainly used for tests with a seed depending on the current day, so that repetition on the same date produce identical series

PF:HACK: Bad solution, need probing of thead and mutex as C++ features as for regex

PF:HACK: Bad solution, need probing of unordered_map as C++ feature as for regex

Typedef Documentation

typedef boost::condition_variable strus::condition_variable
typedef uint64_t strus::double_net_t
typedef uint32_t strus::float_net_t
typedef boost::mutex strus::mutex
typedef boost::recursive_mutex strus::recursive_mutex
typedef boost::unique_lock<boost::recursive_mutex> strus::recursive_unique_lock
typedef boost::mutex::scoped_lock strus::scoped_lock
typedef boost::thread strus::thread
typedef boost::unique_lock<boost::mutex> strus::unique_lock

Enumeration Type Documentation

anonymous enum
Enumerator
B11111111 
B01111111 
B00111111 
B00011111 
B00001111 
B00000111 
B00000011 
B00000001 
B00000000 
B10000000 
B11000000 
B11100000 
B11110000 
B11111000 
B11111100 
B11111110 
B11011111 
B11101111 
B11110111 
B11111011 
B11111101 

Application error codes beyond errno (>= 200)

Enumerator
ErrorCodeUnknown 
ErrorCodeErrno 
ErrorCodeOutOfMem 
ErrorCodeDataCorruption 
ErrorCodeMutexLockFailed 
ErrorCodeLogicError 
ErrorCodeUncaughtException 
ErrorCodeAvailability 
ErrorCodeNotAllowed 
ErrorCodeProtocolError 
ErrorCodePlatformIncompatibility 
ErrorCodePlatformRequirements 
ErrorCodeSyntax 
ErrorCodeNotFound 
ErrorCodeIOError 
ErrorCodeVersionMismatch 
ErrorCodeInvalidArgument 
ErrorCodeInvalidRegex 
ErrorCodeInvalidOperation 
ErrorCodeInvalidFilePath 
ErrorCodeLoadModuleFailed 
ErrorCodeNotImplemented 
ErrorCodeIncompleteInitialization 
ErrorCodeIncompleteDefinition 
ErrorCodeIncompleteConfiguration 
ErrorCodeBindingLanguageError 
ErrorCodeUnknownIdentifier 
ErrorCodeOperationOrder 
ErrorCodeValueOutOfRange 
ErrorCodeMaxLimitReached 
ErrorCodeBufferOverflow 
ErrorCodeMaxNofItemsExceeded 
ErrorCodeMaxRecursionDepht 
ErrorCodeRuntimeError 
ErrorCodeIncompleteRequest 
ErrorCodeIncompleteResult 
ErrorCodeUnexpectedEof 
ErrorCodeHiddenError 
ErrorCodeInputFormat 
ErrorCodeEncoding 
ErrorCodeRequestResolveError 
ErrorCodeNotAcceptable 
Enumerator
NumParseOk 
NumParseErrNoMem 
NumParseErrConversion 
NumParseErrOutOfRange 
NumParseErrInvalidArg 
Enumerator
StringConvOk 
StringConvErrNoMem 
StringConvErrConversion 

Function Documentation

bool strus::addConfigStringItem ( std::string &  config,
const std::string &  key,
const std::string &  value,
ErrorBufferInterface *  errorhnd 
)
void strus::aligned_free ( void *  ptr)
void* strus::aligned_malloc ( std::size_t  size,
std::size_t  alignment 
)
int strus::appendFile ( const std::string &  filename,
const std::string &  content 
)

Appends a string to a file creating the file if it does not exist.

Parameters
[in]filenamethe name of the file to append to
[out]contentcontent of the string to write
Returns
0 on success, errno on failure
bool strus::caseInsensitiveEquals ( const std::string &  val1,
const std::string &  val2 
)

Compare on Ascii letter caseinsensitive equality.

Parameters
[in]val1input string
[in]val2other input string
Returns
true if strings are equal, false else
bool strus::caseInsensitiveStartsWith ( const std::string &  val,
const std::string &  prefix 
)

Test prefix on Ascii letter caseinsensitive equality.

Parameters
[in]valinput string
[in]prefixprefix to check
Returns
true if string starts with prefix, false else
int strus::changeDir ( const std::string &  dirname)

Change current directory of the process.

Parameters
[in]dirnamepath of directory to create
Returns
0 on success, errno on failure
DebugTraceInterface* strus::createDebugTrace_standard ( std::size_t  maxNofThreads_)

Create an debug trace interface.

Parameters
[in]maximumnumber of threads simultaneously writing to and reading from the error buffer interface
int strus::createDir ( const std::string &  dirname,
bool  fail_ifexist = true 
)

Creates a directory if it does not exist yet.

Parameters
[in]dirnamepath of directory to create
[in]fail_ifexistreturn an error if the directory already exists
Returns
0 on success, errno on failure
ErrorBufferInterface* strus::createErrorBuffer_standard ( FILE *  logfilehandle,
std::size_t  maxNofThreads_,
DebugTraceInterface *  debugTrace 
)

Create an error buffer interface.

Parameters
[in]logfilehandlewhere to log error messages
[in]maximumnumber of threads simultaneously writing to and reading from the error buffer interface
[in]debugTracedebug trace interface to use or NULL if undefined, (passed with ownership)
FileLocatorInterface* strus::createFileLocator_std ( ErrorBufferInterface *  errorhnd)

Create a file locator interface.

Parameters
[in]errorhnderror buffer interface
Returns
the file locator (with ownership)
char strus::dirSeparator ( )

Get the OS path element separator.

Returns
the separator
double strus::doubleFromString ( const std::string &  numstr,
NumParseError &  err 
)

Parsing a double precision floating point number from an Ascii string.

Parameters
[in]numstrthe number to parse as Ascii string
[out]errerror code in case of an error, unchanged in case of success
Returns
the number parsed as a double precision floating point number or 0 in case of an error
double strus::doubleFromString ( const char *  numstr,
std::size_t  numsize,
NumParseError &  err 
)

Parsing a double precision floating point number from an Ascii string.

Parameters
[in]numstrthe pointer to the number to parse as Ascii string
[in]numsizethe size of numstr in bytes
[out]errerror code in case of an error, unchanged in case of success
Returns
the number parsed as a double precision floating point number or 0 in case of an error
bool strus::dumpDebugTrace ( DebugTraceInterface *  debugTrace,
const char *  filename 
)

Dump the trace content in a convenient form to a file specified.

Parameters
[in]debugTracedebug trace to dump for the current thread
[in]filenamename of file to dump to, stderr if NULL is specified
int strus::errorCodeFromMessage ( char const *&  msgitr)

Get the next error code in an error message printed by the standard error buffer implementation provided here.

Parameters
[in,out]msgitrpointer to error message in, pointer to position after the error code extracted
Returns
error code >= 0 or -1 if no error code found
const char* strus::errorCodeToString ( int  errcode)

Get the error message as string.

Parameters
[in]errcodeerror number (errno or strus::ErrorCode)
Returns
error message string
int strus::execv_tostring ( const char *  filename,
const char *const  argv[],
std::string &  output 
)

Execution of a command appending the output to a string.

Parameters
[in]filenamepath of program to execute
[in]argvNULL terminated list of arguments to pass to program
[out]outputwhere to append the standard output to
Returns
0 on success, errno on failure
int strus::execve_tostring ( const char *  filename,
const char *const  argv[],
const std::map< std::string, std::string > &  env,
std::string &  output 
)

Execution of a command with some environment variables set, appending the output to a string.

Parameters
[in]filenamepath of program to execute
[in]argvNULL terminated list of arguments to pass to program
[in]envmap of environment variables to set for the command execution
[out]outputwhere to append the standard output to
Returns
0 on success, errno on failure
int strus::expandFilePattern ( const std::string &  pathPattern,
std::vector< std::string > &  res 
)

Get all items matching a file path pattern (with '?' and '*' as substitutes)

Parameters
[in]pathPatternfile path pattern
[out]resthe returned matching paths
Returns
0 on success, errno on failure
bool strus::extractBooleanFromConfigString ( bool &  val,
std::string &  config,
const char *  key,
ErrorBufferInterface *  errorhnd 
)
bool strus::extractFloatFromConfigString ( double &  val,
std::string &  config,
const char *  key,
ErrorBufferInterface *  errorhnd 
)
bool strus::extractStringArrayFromConfigString ( std::vector< std::string > &  val,
std::string &  config,
const char *  key,
char  separator,
ErrorBufferInterface *  errorhnd 
)
bool strus::extractStringFromConfigString ( std::string &  val,
std::string &  config,
const char *  key,
ErrorBufferInterface *  errorhnd 
)
bool strus::extractUIntFromConfigString ( unsigned int &  val,
std::string &  config,
const char *  key,
ErrorBufferInterface *  errorhnd 
)
int strus::getAncestorPath ( const std::string &  path,
int  level,
std::string &  dest 
)

Get an ancestor (containing) path of a file or directory.

Parameters
[in]pathfile system path to get the containing path
[in]levelhow many levels to step back (level == 1 => getParentPath)
[out]destthe containing path
Returns
0 on success, errno on failure
std::vector<std::pair<std::string,std::string> > strus::getAssignmentListItems ( const std::string &  config,
ErrorBufferInterface *  errorhnd 
)
std::vector<std::pair<std::string,std::string> > strus::getConfigStringItems ( const std::string &  config,
ErrorBufferInterface *  errorhnd 
)
int strus::getenv ( const std::string &  var,
std::string &  output 
)

Read an environment variable value as string.

Parameters
[in]varenvironment variable name
[out]outputwhere to write the value to
Returns
0 on success, errno on failure
int strus::getenv_list ( const std::string &  var,
char  sep,
std::vector< std::string > &  output 
)

Read an environment variable value as array of strings, separated by a separator character.

Parameters
[in]varenvironment variable name
[in]sepseparator character separating the list elements
[out]outputwhere to append the values to
Returns
0 on success, errno on failure
int strus::getFileExtension ( const std::string &  path,
std::string &  ext 
)

Get the extension (including '.') of a file or directory.

Parameters
[in]pathfile system path to get the extension from
[out]extthe extension
Returns
0 on success, errno on failure
int strus::getFileName ( const std::string &  path,
std::string &  dest,
bool  withExtension = true 
)

Get the file name without parent path of a file or directory.

Parameters
[in]pathfile system path to get the file name from
[out]destthe file name
Returns
0 on success, errno on failure
int strus::getParentPath ( const std::string &  path,
std::string &  dest 
)

Get the parent (containing) path of a file or directory.

Parameters
[in]pathfile system path to get the containing path
[out]destthe containing path
Returns
0 on success, errno on failure
std::vector<std::pair<std::string,std::string> > strus::getSubConfigStringItems ( const std::string &  configelem,
ErrorBufferInterface *  errorhnd 
)
bool strus::hasUpdirReference ( const std::string &  path)

Return true, if the path contains an upper directory reference '..'.

Parameters
[in]pathfile system path
Returns
true if yes
int64_t strus::intFromString ( const std::string &  numstr,
int64_t  maxvalue,
NumParseError &  err 
)

Parsing an integer number from an Ascii string.

Parameters
[in]numstrthe number to parse as Ascii string
[in]maxvaluethe maximum value accepted for the result
[out]errerror code in case of an error, unchanged in case of success
Returns
the number parsed as an integer or 0 in case of an error
int64_t strus::intFromString ( const char *  numstr,
std::size_t  numsize,
int64_t  maxvalue,
NumParseError &  err 
)

Parsing an integer number from an Ascii string.

Parameters
[in]numstrthe pointer to the number to parse as Ascii string
[in]numsizethe size of numstr in bytes
[in]maxvaluethe maximum value accepted for the result
[out]errerror code in case of an error, unchanged in case of success
Returns
the number parsed as an integer or 0 in case of an error
bool strus::isAbsolutePath ( const std::string &  path)

Check if a file system path is a path starting the file system root '/'.

Returns
true, if yes
Parameters
[in]pathfile system path to check
bool strus::isDir ( const std::string &  path)

Check if a file system path points to a directory.

Parameters
[in]pathfile system path to check
Returns
true, if yes
bool strus::isEmptyString ( const char *  val,
std::size_t  size 
)

Evaluate if a string is empty or contains only space characters.

Parameters
[in]valpointer to input string
[in]sizesize of to input string in bytes
Returns
true if string is empty
bool strus::isEmptyString ( const std::string &  val)

Evaluate if a string is empty or contains only space characters.

Parameters
[in]valinput string
Returns
true if string is empty
bool strus::isExplicitPath ( const std::string &  path)

Check if a file path is explicit (relative path or absolute path)

Returns
true, if yes
Parameters
[in]pathfile system path to check
bool strus::isFile ( const std::string &  path)

Check if a file system path points to a file.

Returns
true, if yes
Parameters
[in]pathfile system path to check
bool strus::isRelativePath ( const std::string &  path)

Check if a file system path is a path starting with a name and not with a directive referencing the current path './' or the file system root '/'.

Returns
true, if yes
Parameters
[in]pathfile system path to check
bool strus::isTextFile ( const std::string &  path)

Check if a file system path points to a file with text content (not binary)

Parameters
[in]pathfile system path to check
Remarks
Implementation uses heuristics of character frequencies for the check. Currently fails on UTF-8 text files of non latin alphabet based languages.
Returns
true, if yes
std::string strus::joinFilePath ( const std::string &  parentpath,
const std::string &  childpath 
)

Join two path with directory separator.

Parameters
[in]parentpathleft part of the resulting file system path
[in]childpathright part of the resulting file system path
Returns
the joined path or empty in case of a memory allocation error
int strus::mkdirp ( const std::string &  dirname)

Creates a directory path (mkdir -p)

Parameters
[in]dirnamepath of directory to create
Returns
0 on success, errno on failure
const char* strus::numstring_error ( NumParseError  errcode)

Convert string conversion error code into an error message string.

Parameters
[in]errcodeerror code
Returns
error message string
std::runtime_error strus::numstring_exception ( NumParseError  errcode)

Convert string conversion error code into an exception.

Parameters
[in]errcodeerror code
Returns
runtime error exception
void strus::printIndentMultilineString ( std::ostream &  out,
std::size_t  indentsize,
const char *  descr,
ErrorBufferInterface *  errorhnd 
)

Print a multiline string with indentiation.

Parameters
[in,out]outprint target
[in]indentsizenumber of steps to indent
[in]descrwhat to print
[in,out]errorhndbuffer for exception error messages
int strus::readDirFiles ( const std::string &  path,
const std::string &  ext,
std::vector< std::string > &  res 
)

Reads all file names matching to the extension ext of a directory to an array of strings.

Parameters
[in]paththe name of director to read
[in]extthe file extension the accepted files must have (empty if all extensions are accepted)
[out]resthe returned matching file names of the directory read
Returns
0 on success, errno on failure
int strus::readDirItems ( const std::string &  path,
std::vector< std::string > &  res 
)

Reads all items (directory or file) of a directory to an array of strings.

Parameters
[in]paththe name of director to read
[out]resthe returned matching items of the directory read
Returns
0 on success, errno on failure
int strus::readDirSubDirs ( const std::string &  path,
std::vector< std::string > &  res 
)

Reads all subdirectories of a directory to an array of strings.

Parameters
[in]paththe name of director to read
[out]resthe returned matching sub directories of the directory read
Returns
0 on success, errno on failure
int strus::readFile ( const std::string &  filename,
std::string &  res 
)

Reads the complete content of a file to a string.

Parameters
[in]filenamethe name of file to read
[out]resthe returned content of the file read
Returns
0 on success, errno on failure
int strus::readFileSize ( const std::string &  filename,
std::size_t &  size 
)

Evaluate the size of a file in bytes.

Parameters
[in]filenamethe name of file to get the filesize of
[out]sizethe returned size
Returns
0 on success, errno on failure
int strus::readStdin ( std::string &  res)

Reads the complete input of stdin to a string.

Parameters
[out]resthe returned content of the file read
Returns
0 on success, errno on failure
int strus::removeDir ( const std::string &  dirname,
bool  fail_ifnofexist = false 
)

Removes an empty directory.

Parameters
[in]dirnamethe name of the directory to remove
[in]fail_ifnofexistreturn an error if the directory does not exist
Returns
0 on success, errno on failure
int strus::removeDirRecursive ( const std::string &  dirname,
bool  fail_ifnofexist = false 
)

Removes a directory with all its contents.

Parameters
[in]dirnamethe name of the directory to remove
[in]fail_ifnofexistreturn an error if the directory does not exist
Returns
0 on success, errno on failure
void strus::removeErrorCodesFromMessage ( char *  msg)

Remove all error codes in an error message printed by the standard error buffer implementation provided here.

Parameters
[in]msgerror message string to process
int strus::removeFile ( const std::string &  filename,
bool  fail_ifnofexist = false 
)

Removes a file.

Parameters
[in]filenamethe name of the file to remove
[in]fail_ifnofexistreturn an error if the directory does not exist
Returns
0 on success, errno on failure
void strus::removeKeysFromConfigString ( std::string &  config,
const char **  keys,
ErrorBufferInterface *  errorhnd 
)
int strus::renameFile ( const std::string &  old_filename,
const std::string &  new_filename 
)

Moves (renames) a file.

Parameters
[in]old_filenamethe name of the file to rename
[in]new_filenamethe new name of the file
Returns
0 on success, errno on failure
int strus::resolveUpdirReferences ( std::string &  path)

Resolve upper directory references in a path, e.g. replace "/home/john/../jack" by "/home/jack".

Parameters
[in,out]pathpath to resolve updir references in
Note
Does not care about permissions, it is just mapping a string to another
Does not care about symbolic links and may do an incorrect transformation when symbolic links are in the path
Remarks
Result gets incorrect when symbolic links are used
Returns
0 on success, errno on failure (ENOMEM,EINVAL)
char strus::separatorPathList ( )

Separator character used for separating file paths in environment variables.

Returns
the separator
Remarks
OS dependent
void strus::sleep ( int  nofsecs)
std::string strus::string_format ( const char *  fmt,
va_list  ap 
)

Get a string built from a format string and arguments.

Parameters
[in]fmtC printf format string
[in]apargument list
Returns
the string built or an empty string in case of a memory allocation error
std::string strus::string_format ( const char *  fmt,
  ... 
)

Get a string built from a format string and arguments.

Parameters
[in]fmtC printf format string
[in]...argument list
Returns
the string built or an empty string in case of a memory allocation error
std::runtime_error strus::stringconv_exception ( StringConvError  errcode)

Convert string conversion error code into an exception.

Parameters
[in]errcodeerror code
bool strus::stringStartsWith ( const std::string &  val,
const std::string &  prefix 
)

Test prefix on equality.

Parameters
[in]valinput string
[in]prefixprefix to check
Returns
true if string starts with prefix, false else
std::string strus::tolower ( const char *  val,
StringConvError &  err 
)

Convert ASCII letters in string to lowercase.

Parameters
[in]valinput string
[out]errerror code in case of error (not set on success)
Returns
converted string or empty string in case of error
std::string strus::tolower ( const char *  val,
std::size_t  size,
StringConvError &  err 
)

Convert ASCII letters in string to lowercase.

Parameters
[in]valinput string
[in]sizeinput string size in bytes
[out]errerror code in case of error (not set on success)
Returns
converted string or empty string in case of error
std::string strus::tolower ( const std::string &  val,
StringConvError &  err 
)

Convert ASCII letters in string to lowercase.

Parameters
[in]valinput string
[out]errerror code in case of error (not set on success)
Returns
converted string or empty string in case of error
std::string strus::trim ( const std::string &  val,
StringConvError &  err 
)

Trim trailing and heading whitespace and control characters.

Parameters
[in]valinput string
[out]errerror code in case of error (not set on success)
Returns
converted string or empty string in case of error
std::string strus::trim ( const char *  val,
std::size_t  size,
StringConvError &  err 
)

Trim trailing and heading whitespace and control characters.

Parameters
[in]valinput string
[in]sizeinput string size in bytes
[out]errerror code in case of error (not set on success)
Returns
converted string or empty string in case of error
uint64_t strus::uintFromString ( const std::string &  numstr,
uint64_t  maxvalue,
NumParseError &  err 
)

Parsing an unsigned integer number from an Ascii string.

Parameters
[in]numstrthe number to parse as Ascii string
[in]maxvaluethe maximum value accepted for the result
[out]errerror code in case of an error, unchanged in case of success
Returns
the number parsed as an unsigned integer or 0 in case of an error
uint64_t strus::uintFromString ( const char *  numstr,
std::size_t  numsize,
uint64_t  maxvalue,
NumParseError &  err 
)

Parsing an unsigned integer number from an Ascii string.

Parameters
[in]numstrthe pointer to the number to parse as Ascii string
[in]numsizethe size of numstr in bytes
[in]maxvaluethe maximum value accepted for the result
[out]errerror code in case of an error, unchanged in case of success
Returns
the number parsed as an unsigned integer or 0 in case of an error
std::string strus::unescape ( const std::string &  val,
StringConvError &  err 
)

Convert excaped control characters to their unescaped form (e.g. \n to
)

Parameters
[in]valinput string
[out]errerror code in case of error (not set on success)
Returns
converted string or empty string in case of error
static unsigned char strus::utf8charlen ( unsigned char  ch)
inlinestatic

Get the lenght of an UTF-8 encoded character from its first byte.

Parameters
[in]thefirst byte of the character
Returns
the length of the character in bytes
std::string strus::utf8clean ( const std::string &  name,
StringConvError &  err 
)

Convert possibly broken UTF-8 to valid UTF-8.

Parameters
[in]valinput string
[out]errerror code in case of error (not set on success)
Returns
converted string or empty string in case of error
int32_t strus::utf8decode ( const char *  itr,
unsigned int  charsize 
)

Decoding of a single UTF-8 character in a string.

std::size_t strus::utf8encode ( char *  buf,
int32_t  chr 
)

Encoding of a single UTF-8 character into a string buffer.

static bool strus::utf8midchr ( unsigned char  ch)
inlinestatic

Return true, if the character passed as argument is a non start character of a multi byte encoded unicode character.

static const char* strus::utf8prev ( char const *  end)
inlinestatic

Skip to the begin of an UTF-8 encoded character from a pointer into it.

Parameters
[in]pointerinto the UTF-8 encoded character
Returns
pointer to the start of the character
int strus::writeFile ( const std::string &  filename,
const std::string &  content 
)

Writes a string to a file creating the file if it does not exist.

Parameters
[in]filenamethe name of the file to write
[out]contentcontent of the string to write
Returns
0 on success, errno on failure