BDS Public
Beamlib 3.3.4
This is the Beam C++ class library.
Loading...
Searching...
No Matches

This class stores and manipulates ASCII strings. More...

#include <BString.h>

Public Member Functions

 BString ()
 
 BString (const BString &string)
 
 BString (const char *str)
 
 BString (const char *str, unsigned int len)
 
 BString (char ch)
 
 BString (BInt v)
 
 BString (BUInt v)
 
 BString (BUInt64 v)
 
 BString (double v)
 
 ~BString ()
 
BString copy () const
 Return an independant copy.
 
int len () const
 Length of string.
 
const char * retStr () const
 Ptr to char* representation.
 
const char * str () const
 Ptr to char* representation.
 
char * retStrDup () const
 Ptr to newly malloc'd char*.
 
int retInt () const
 Return string as a int.
 
unsigned int retUInt () const
 Return string as a int.
 
double retDouble () const
 Return string as a double.
 
BFloat64 retFloat64 () const
 Return string as a BFloat64.
 
int compare (const BString &string) const
 Compare strings. Returns 0 for match.
 
int compareWild (const BString &string) const
 Compare string to string with wildcards . Returns 0 for match.
 
int compareWildExpression (const BString &string) const
 Compare string to space deliminated patterns. Returns 0 for match.
 
int compareRegex (const BString &pattern, int ignoreCase=0) const
 Compare strings. Returns 1 for match.
 
BStringtruncate (int len)
 Truncate to length len.
 
BStringpad (int len)
 Pad to length len.
 
void clear ()
 Clear the string.
 
BStringtoUpper ()
 Convert to uppercase.
 
BStringtoLower ()
 Convert to lowercase.
 
BString lowerFirst ()
 Return string with lowercase first character.
 
void removeNL ()
 Remove if present NL from last char.
 
BString justify (int leftMargin, int width)
 Justify the string to the given width.
 
BString fixedLen (int length, int rightJustify=0)
 return string formated to fixed length
 
BString firstLine ()
 Return first line.
 
BString translateChar (char ch, BString replace=" ")
 Translate character converting them to the given string.
 
BString reverse () const
 Reverse character order.
 
BString subString (int start, int len) const
 Returns substring.
 
int del (int start, int len)
 Delete substring.
 
int insert (int start, BString str)
 Insert substring.
 
int append (const BString &str)
 Append a string.
 
BString add (const BString &str) const
 Add strings returning result.
 
BStringprintf (const char *fmt,...)
 Formated print into the string.
 
int find (char ch) const
 Find ch in string searching forwards. Returns -1 if not found.
 
int find (BString str) const
 Find string in string searching forwards. Returns -1 if not found.
 
int findReverse (char ch) const
 Find ch in string searching backwards. Returns -1 if not found.
 
BString csvEncode () const
 Encode a string for CSV.
 
BStringcsvDecode (const BString str)
 Decode a string from CSV.
 
BString base64Encode () const
 Encode a string to base64.
 
BError base64Decode (BString &str) const
 Decode a string from base64.
 
BList< BStringgetTokenList (BString separators)
 Break string into tokens.
 
BList< BStringgetTokenList (char separator)
 Break string into tokens.
 
BString removeSeparators (BString separators)
 Remove any char from sepatators from string.
 
BString pullToken (BString terminators)
 Pull token from start of string.
 
BString pullSeparators (BString separators)
 Pull separators from start of string.
 
BString pullWord ()
 Pull a word out of the head of the string.
 
BString pullLine ()
 Pull a line out of the head of the string.
 
BList< BStringsplit (char splitChar)
 Split string into an array based on the character separator.
 
BString dirname ()
 Return the directory component if the string is a file path name.
 
BString filename ()
 Return the filename component if the string is a file path name.
 
BString basename ()
 Return the file name component if the string is a file path name.
 
BString extension ()
 Return the file extension component if the string is a file path name.
 
BString extensionFull ()
 Return the file extension component with leading '.' if the string is a file path name.
 
BUInt32 hash () const
 Create a 32bit hash number for the string.
 
char & get (int pos)
 Return the character at the position give. Will print an error message and raise the SIGABORT exception if out of range.
 
const char & get (int pos) const
 Return the character at the position give. Will print an error message and raise the SIGABORT exception if out of range.
 
BStringoperator= (const BString &string)
 
char & operator[] (int pos)
 
int operator== (const BString &s) const
 
int operator== (const char *s) const
 
int operator> (const BString &s) const
 
int operator> (const char *s) const
 
int operator< (const BString &s) const
 
int operator< (const char *s) const
 
int operator>= (const BString &s) const
 
int operator<= (const BString &s) const
 
int operator!= (const BString &s) const
 
int operator!= (const char *s) const
 
BString operator+ (const BString &s) const
 
BString operator+ (const char *s) const
 
BString operator+= (const BString &s)
 
BString operator+= (const char *s)
 
BString operator+ (char ch) const
 
BString operator+ (BInt i) const
 
BString operator+ (BUInt i) const
 
BString operator+ (BUInt64 i) const
 
 operator const char * () const
 
BString field (int field) const
 Depreciated function.
 
char ** fields ()
 Depreciated function.
 

Static Public Member Functions

static BString convert (char ch)
 Converts char to string.
 
static BString convert (BInt value)
 Converts int to string.
 
static BString convert (BUInt value)
 Converts uint to string.
 
static BString convert (double value, int eFormat=0)
 Converts double to string.
 
static BString convert (BUInt64 value)
 Converts long long to string.
 
static BString convertHex (BInt value)
 Converts int to string as hex value.
 
static BString convertHex (BUInt value)
 Converts uint to string as hex value.
 

Protected Attributes

BRefDataostr
 This is the reference counted string storage.
 

Detailed Description

This class stores and manipulates ASCII strings.

The BString class is designed for the storage and manipulation of variable length ASCII strings. It uses the BRefData class to store the null terminated strings in shared and references counted shared memory areas on the heap. This efficient method reduces memory allocation, deallocation and copying. Copying or just passing a string in and out of a function becomes a simple pointer copy with the string data reference count incremented.

You can convert a BStirng to a const char* using the BString::str() method. You can create a BString from a char* with its constructor BString(const char*) which is used implicitly for conversions. The BString also supports conversion to and from Qt QStrings if the Qt headers are included before the BString.h header. The BString also supports input and output from std::iostream objects.

As well as its constructor function, BString supports a number of explicity convert() functions that can convert basic types such as integers to a BString. There are also some ret*() functions to parse the BString for integer and floating point values.

The operators: =, +, <, >, >=, <=, ==, != operate as you would expect with the +" appending strings.

Constructor & Destructor Documentation

◆ BString() [1/9]

BString::BString ( )

◆ BString() [2/9]

BString::BString ( const BString string)

◆ BString() [3/9]

BString::BString ( const char *  str)

◆ BString() [4/9]

BString::BString ( const char *  str,
unsigned int  len 
)

◆ BString() [5/9]

BString::BString ( char  ch)

◆ BString() [6/9]

BString::BString ( BInt  v)

◆ BString() [7/9]

BString::BString ( BUInt  v)

◆ BString() [8/9]

BString::BString ( BUInt64  v)

◆ BString() [9/9]

BString::BString ( double  v)

◆ ~BString()

BString::~BString ( )

Member Function Documentation

◆ convert() [1/5]

BString BString::convert ( char  ch)
static

Converts char to string.

◆ convert() [2/5]

BString BString::convert ( BInt  value)
static

Converts int to string.

◆ convert() [3/5]

BString BString::convert ( BUInt  value)
static

Converts uint to string.

◆ convert() [4/5]

BString BString::convert ( double  value,
int  eFormat = 0 
)
static

Converts double to string.

◆ convert() [5/5]

BString BString::convert ( BUInt64  value)
static

Converts long long to string.

◆ convertHex() [1/2]

BString BString::convertHex ( BInt  value)
static

Converts int to string as hex value.

◆ convertHex() [2/2]

BString BString::convertHex ( BUInt  value)
static

Converts uint to string as hex value.

◆ copy()

BString BString::copy ( ) const

Return an independant copy.

◆ len()

int BString::len ( ) const

Length of string.

◆ retStr()

const char * BString::retStr ( ) const

Ptr to char* representation.

◆ str()

const char * BString::str ( ) const

Ptr to char* representation.

◆ retStrDup()

char * BString::retStrDup ( ) const

Ptr to newly malloc'd char*.

◆ retInt()

int BString::retInt ( ) const

Return string as a int.

◆ retUInt()

unsigned int BString::retUInt ( ) const

Return string as a int.

◆ retDouble()

double BString::retDouble ( ) const

Return string as a double.

◆ retFloat64()

BFloat64 BString::retFloat64 ( ) const

Return string as a BFloat64.

◆ compare()

int BString::compare ( const BString string) const

Compare strings. Returns 0 for match.

◆ compareWild()

int BString::compareWild ( const BString string) const

Compare string to string with wildcards . Returns 0 for match.

◆ compareWildExpression()

int BString::compareWildExpression ( const BString string) const

Compare string to space deliminated patterns. Returns 0 for match.

◆ compareRegex()

int BString::compareRegex ( const BString pattern,
int  ignoreCase = 0 
) const

Compare strings. Returns 1 for match.

◆ truncate()

BString & BString::truncate ( int  len)

Truncate to length len.

◆ pad()

BString & BString::pad ( int  len)

Pad to length len.

◆ clear()

void BString::clear ( )

Clear the string.

◆ toUpper()

BString & BString::toUpper ( )

Convert to uppercase.

◆ toLower()

BString & BString::toLower ( )

Convert to lowercase.

◆ lowerFirst()

BString BString::lowerFirst ( )

Return string with lowercase first character.

◆ removeNL()

void BString::removeNL ( )

Remove if present NL from last char.

◆ justify()

BString BString::justify ( int  leftMargin,
int  width 
)

Justify the string to the given width.

◆ fixedLen()

BString BString::fixedLen ( int  length,
int  rightJustify = 0 
)

return string formated to fixed length

◆ firstLine()

BString BString::firstLine ( )

Return first line.

◆ translateChar()

BString BString::translateChar ( char  ch,
BString  replace = " " 
)

Translate character converting them to the given string.

◆ reverse()

BString BString::reverse ( ) const

Reverse character order.

◆ subString()

BString BString::subString ( int  start,
int  len 
) const

Returns substring.

◆ del()

int BString::del ( int  start,
int  len 
)

Delete substring.

◆ insert()

int BString::insert ( int  start,
BString  str 
)

Insert substring.

◆ append()

int BString::append ( const BString str)

Append a string.

◆ add()

BString BString::add ( const BString str) const

Add strings returning result.

◆ printf()

BString & BString::printf ( const char *  fmt,
  ... 
)

Formated print into the string.

◆ find() [1/2]

int BString::find ( char  ch) const

Find ch in string searching forwards. Returns -1 if not found.

◆ find() [2/2]

int BString::find ( BString  str) const

Find string in string searching forwards. Returns -1 if not found.

◆ findReverse()

int BString::findReverse ( char  ch) const

Find ch in string searching backwards. Returns -1 if not found.

◆ csvEncode()

BString BString::csvEncode ( ) const

Encode a string for CSV.

◆ csvDecode()

BString & BString::csvDecode ( const BString  str)

Decode a string from CSV.

◆ base64Encode()

BString BString::base64Encode ( ) const

Encode a string to base64.

◆ base64Decode()

BError BString::base64Decode ( BString str) const

Decode a string from base64.

◆ getTokenList() [1/2]

BList< BString > BString::getTokenList ( BString  separators)

Break string into tokens.

◆ getTokenList() [2/2]

BList< BString > BString::getTokenList ( char  separator)

Break string into tokens.

◆ removeSeparators()

BString BString::removeSeparators ( BString  separators)

Remove any char from sepatators from string.

◆ pullToken()

BString BString::pullToken ( BString  terminators)

Pull token from start of string.

◆ pullSeparators()

BString BString::pullSeparators ( BString  separators)

Pull separators from start of string.

◆ pullWord()

BString BString::pullWord ( )

Pull a word out of the head of the string.

◆ pullLine()

BString BString::pullLine ( )

Pull a line out of the head of the string.

◆ split()

BList< BString > BString::split ( char  splitChar)

Split string into an array based on the character separator.

◆ dirname()

BString BString::dirname ( )

Return the directory component if the string is a file path name.

◆ filename()

BString BString::filename ( )

Return the filename component if the string is a file path name.

◆ basename()

BString BString::basename ( )

Return the file name component if the string is a file path name.

◆ extension()

BString BString::extension ( )

Return the file extension component if the string is a file path name.

◆ extensionFull()

BString BString::extensionFull ( )

Return the file extension component with leading '.' if the string is a file path name.

◆ hash()

BUInt32 BString::hash ( ) const

Create a 32bit hash number for the string.

◆ get() [1/2]

char & BString::get ( int  pos)

Return the character at the position give. Will print an error message and raise the SIGABORT exception if out of range.

◆ get() [2/2]

const char & BString::get ( int  pos) const

Return the character at the position give. Will print an error message and raise the SIGABORT exception if out of range.

◆ operator=()

BString & BString::operator= ( const BString string)

◆ operator[]()

char & BString::operator[] ( int  pos)

◆ operator==() [1/2]

int BString::operator== ( const BString s) const
inline

◆ operator==() [2/2]

int BString::operator== ( const char *  s) const
inline

◆ operator>() [1/2]

int BString::operator> ( const BString s) const
inline

◆ operator>() [2/2]

int BString::operator> ( const char *  s) const
inline

◆ operator<() [1/2]

int BString::operator< ( const BString s) const
inline

◆ operator<() [2/2]

int BString::operator< ( const char *  s) const
inline

◆ operator>=()

int BString::operator>= ( const BString s) const
inline

◆ operator<=()

int BString::operator<= ( const BString s) const
inline

◆ operator!=() [1/2]

int BString::operator!= ( const BString s) const
inline

◆ operator!=() [2/2]

int BString::operator!= ( const char *  s) const
inline

◆ operator+() [1/6]

BString BString::operator+ ( const BString s) const
inline

◆ operator+() [2/6]

BString BString::operator+ ( const char *  s) const
inline

◆ operator+=() [1/2]

BString BString::operator+= ( const BString s)
inline

◆ operator+=() [2/2]

BString BString::operator+= ( const char *  s)
inline

◆ operator+() [3/6]

BString BString::operator+ ( char  ch) const
inline

◆ operator+() [4/6]

BString BString::operator+ ( BInt  i) const
inline

◆ operator+() [5/6]

BString BString::operator+ ( BUInt  i) const
inline

◆ operator+() [6/6]

BString BString::operator+ ( BUInt64  i) const
inline

◆ operator const char *()

BString::operator const char * ( ) const
inline

◆ field()

BString BString::field ( int  field) const

Depreciated function.

◆ fields()

char ** BString::fields ( )

Depreciated function.

Member Data Documentation

◆ ostr

BRefData* BString::ostr
protected

This is the reference counted string storage.


The documentation for this class was generated from the following files: