Humble Framework for SkyOS


Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

HStr< MAX_LEN > Class Template Reference
[Base]

#include <HString.h>

Inheritance diagram for HStr< MAX_LEN >:

HObj

Detailed Description

template<uint32 MAX_LEN>
class HStr< MAX_LEN >

The HStr class is a template class that allocates a fixed size buffer, and then wraps many of the standard RTL string functions. Although strings of theoretically any length can be declared, this class is really intended for smaller (< 4KB) strings. Since the buffer is pre-allocated to the maximum allowed length--plus the terminator--this class can be very memory inefficient if abused.

Although this code has been completely rewritten, it was originally inspired byte the CWizCharString published by Poul Costinsky at www.codeproject.com.

Definition at line 835 of file HString.h.

Public Member Functions

 HStr (HStr const &T)
 HStr (StringPtr pstr)
HStrAlign (HString::Alignment align, uint32 uWidth, Text chPad= ' ') throw ()
 Align the string to a given width.
ErrCode Append (StringPtr pstr)
 Appends one string onto the end of this string.
int32 Compare (const HStr &rhs, bool bCase=true) const
 Compares this string to another string.
int32 Compare (StringPtr pstr, bool bCase=true) const
 Compares this string to another string.
int32 Find (Text ch, uint32 uStart=0) const
 Searches for the first ocurrence of a character.
int32 Find (StringPtr pstr, uint32 uStart=0) const
 Searches for the first ocurrence of a string.
int32 FindLast (Text ch) const
 Searches for the last occurrence of a character.
int32 Format (StringPtr pstr,...)
 Formats the string using a sprintf()-style syntax.
HStr< MAX_LEN > Left (uint32 uCount) const
 Returns a portion of the string.
HStrMakeLower (void)
 Converts the string to all lower case.
HStrMakeUpper (void)
 Converts the string to all upper case (capitals).
HStr< MAX_LEN > Mid (uint32 uStart, int32 nCount=-1) const
 Returns a portion of the string.
int32 Replace (Text chOld, Text chNew)
 Replaces all ocurrences of one character with another.
HStr< MAX_LEN > Right (uint32 uCount) const
 Returns a portion of the string.
HStrTrim (void)
 Trims all whitespace--front and back--from the string.
HStrTrimLeft (void)
 Trims all whitespace at the front of the string.
HStrTrimRight (void)
 Trims all whitespace at the end of the string.
Text GetAt (int32 index) const
 Returns the character at a given offset, or zero if offset is out of bounds.
void SetAt (int32 index, Text ch)
 Sets the character at a given offset.
int32 GetLength (void) const
 Returns length of the string in characters.
StringPtr GetString (void) const
 Returns a ptr to the underlying buffer.
int32 GetValue (void) const
 Returns an integer value for the string.
void SetEmpty (void)
 Sets the string to an empty (zero-length) string.
int32 FormatV (StringPtr pstr, va_list &vaList)
 Formats the string using a sprintf()-style syntax.
uint32 Hash (void) const
 Returns a 32-bit hash value for the string.
bool IsEmpty (void) const
 Evaluates to true if the string is empty, i.e., zero-length.
bool IsNotEmpty (void) const
 Evaluates to true if the string is not empty.
bool operator== (StringPtr pstr) const
bool operator!= (StringPtr pstr) const
bool operator<= (StringPtr pstr) const
bool operator< (StringPtr pstr) const
bool operator>= (StringPtr pstr) const
bool operator> (StringPtr pstr) const
 operator StringPtr () const
Text operator[] (int index) const
HStroperator= (HStr const &rhs)
HStroperator= (StringPtr pstr)
HStroperator+= (HStr const &rhs)
HStroperator+= (StringPtr pstr)
HStr operator+ (HStr const &rhs) const
HStr operator+ (StringPtr pstr) const

Static Public Member Functions

static int32 GetMaxLength (void)
 Returns the maximum length of the string buffer (not including '\0').

Protected Member Functions

void assign (StringPtr pstr)
 Sets the managed string to the given string.
bool isValidIndex (uint32 udx) const
 Evaluates if an offset is within the buffer.
bool validPtr (StringPtr pstr) const
 Evaluate a string ptr for validity.

Protected Attributes

Text m_buffer [MAX_LEN+1]
 buffer to store the text


Member Function Documentation

template<uint32 MAX_LEN>
HStr& HStr< MAX_LEN >::Align HString::Alignment  align,
uint32  uWidth,
Text  chPad = ' '
throw ()
 

Returns:
Reference to the aligned string
Parameters:
align Alignment (ALIGN_* constant)
uWidth Width of string
chPad Pad character (defaults to space)

Definition at line 870 of file HString.h.

template<uint32 MAX_LEN>
ErrCode HStr< MAX_LEN >::Append StringPtr  pstr  ) 
 

Returns:
Always NO_ERROR
Parameters:
pstr String to Append

Definition at line 927 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::Compare const HStr< MAX_LEN > &  rhs,
bool  bCase = true
const
 

Returns:
Zero if strings are equal, non-zero otherwise
Parameters:
rhs HStr object to compare against
bCase True if comparison is case-sensitive, false otherwise

Definition at line 940 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::Compare StringPtr  pstr,
bool  bCase = true
const
 

Returns:
Zero if strings are equal, non-zero otherwise
Parameters:
pstr Ptr to string to compare against
bCase True if comparison is case-sensitive, false otherwise

Definition at line 954 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::Find Text  ch,
uint32  uStart = 0
const
 

Scans the string and returns the offset to the first ocurrence of a given character. This method will work as expected if scanning for the '\0' character.

Returns:
Offset to character, or -1 if not found
Parameters:
ch Character to find
uStart Offset to start from (defaults to 0)

Definition at line 973 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::Find StringPtr  pstr,
uint32  uStart = 0
const
 

Scans the string and returns the offset to the first ocurrence of a given string.

Returns:
Offset of character, or -1 if not found
Parameters:
pstr Ptr to string to find
uStart Position to start from

Definition at line 993 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::FindLast Text  ch  )  const
 

Scans the string—back to front—and returns a ptr to the last occurrence of a given character. This method will work as expected if scanning for the '\0' character.

Returns:
Offset of character, or -1 if not found
Parameters:
ch Character to find

Definition at line 1016 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::Format StringPtr  pstr,
  ...
 

Returns:
Length of formatted string in characters
Parameters:
pstr Format text with optional printf-style arguments

Definition at line 1031 of file HString.h.

template<uint32 MAX_LEN>
HStr<MAX_LEN> HStr< MAX_LEN >::Left uint32  uCount  )  const
 

This method returns a fixed count of characters, beginning at the start of the string. If the requested count is longer than the string, then the entire string is returned.

Returns:
New string
Parameters:
uCount Count of characters to be returned

Definition at line 1053 of file HString.h.

template<uint32 MAX_LEN>
HStr& HStr< MAX_LEN >::MakeLower void   ) 
 

Returns:
Reference to this object

Definition at line 1070 of file HString.h.

template<uint32 MAX_LEN>
HStr& HStr< MAX_LEN >::MakeUpper void   ) 
 

Returns:
Reference to this object

Definition at line 1080 of file HString.h.

template<uint32 MAX_LEN>
HStr<MAX_LEN> HStr< MAX_LEN >::Mid uint32  uStart,
int32  nCount = -1
const
 

This method returns a fixed count of characters, beginning at a given offset. If the requested count is longer than the remaining portion of the string (or is negative), then the remainder of the string is returned.

Returns:
New string
Parameters:
uStart Starting offset
nCount Count of characters to be returned (-1 for the remainder)

Definition at line 1097 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::Replace Text  chOld,
Text  chNew
 

Scans the string, replacing all occurrences of chOld with chNew, then returns the count of characters replaced.

Returns:
Count of characters replaced
Parameters:
chOld Character to replace
chNew Character to replace chOld with

Definition at line 1118 of file HString.h.

template<uint32 MAX_LEN>
HStr<MAX_LEN> HStr< MAX_LEN >::Right uint32  uCount  )  const
 

This method returns a fixed count of characters, beginning at the end of the string. If the requested count is longer than the string, then the entire string is returned.

Returns:
New string
Parameters:
uCount Count of characters to be returned

Definition at line 1142 of file HString.h.

template<uint32 MAX_LEN>
HStr& HStr< MAX_LEN >::Trim void   ) 
 

Returns:
Reference to this object

Definition at line 1159 of file HString.h.

template<uint32 MAX_LEN>
HStr& HStr< MAX_LEN >::TrimLeft void   ) 
 

Returns:
Reference to this object

Definition at line 1170 of file HString.h.

template<uint32 MAX_LEN>
HStr& HStr< MAX_LEN >::TrimRight void   ) 
 

Returns:
Reference to the trimmed string

Definition at line 1191 of file HString.h.

template<uint32 MAX_LEN>
void HStr< MAX_LEN >::assign StringPtr  pstr  )  [protected]
 

Parameters:
pstr Ptr to string to set

Definition at line 1208 of file HString.h.

template<uint32 MAX_LEN>
Text HStr< MAX_LEN >::GetAt int32  index  )  const
 

Returns:
Character at offset
Parameters:
index Index of character

Definition at line 1224 of file HString.h.

template<uint32 MAX_LEN>
void HStr< MAX_LEN >::SetAt int32  index,
Text  ch
 

Parameters:
index Index
ch Character to set

Definition at line 1229 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::GetLength void   )  const
 

Returns:
Length of the string

Definition at line 1236 of file HString.h.

template<uint32 MAX_LEN>
static int32 HStr< MAX_LEN >::GetMaxLength void   )  [static]
 

Returns:
Count (in bytes)

Definition at line 1240 of file HString.h.

template<uint32 MAX_LEN>
StringPtr HStr< MAX_LEN >::GetString void   )  const
 

Returns:
Ptr to string

Definition at line 1244 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::GetValue void   )  const
 

Returns:
Integer value of the string

Definition at line 1248 of file HString.h.

template<uint32 MAX_LEN>
int32 HStr< MAX_LEN >::FormatV StringPtr  pstr,
va_list &  vaList
 

Returns:
Length of the formatted string in characters
Parameters:
pstr Format text with optional printf-style arguments
vaList Variable list of arguments

Definition at line 1263 of file HString.h.

template<uint32 MAX_LEN>
uint32 HStr< MAX_LEN >::Hash void   )  const
 

Returns:
Hash value

Definition at line 1269 of file HString.h.

template<uint32 MAX_LEN>
bool HStr< MAX_LEN >::IsEmpty void   )  const
 

Returns:
True if empty string

Definition at line 1275 of file HString.h.

template<uint32 MAX_LEN>
bool HStr< MAX_LEN >::IsNotEmpty void   )  const
 

Returns:
True if string is at least 1 character in length

Definition at line 1281 of file HString.h.

template<uint32 MAX_LEN>
bool HStr< MAX_LEN >::isValidIndex uint32  udx  )  const [protected]
 

This returns true if the given offset is within the bounds of the buffer. It is independent of the string's length, i.e., will still return true if past the '\0' terminator (but still within MAX_LEN).

Returns:
True if value is within buffer
Parameters:
udx Value to test

Definition at line 1294 of file HString.h.

template<uint32 MAX_LEN>
bool HStr< MAX_LEN >::validPtr StringPtr  pstr  )  const [protected]
 

To be considered valid, a ptr must be non-NULL, but also different from the buffer itself (to stop self-assignment or overlapping copy operations).

Returns:
True if ptr is valid
Parameters:
pstr Ptr to evaluate

Definition at line 1305 of file HString.h.


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

2006.01.09-16:37