RakNet  4.0
Public Member Functions | Static Public Member Functions | List of all members
RakNet::RakString Class Reference

String class. More...

#include <RakString.h>

Public Member Functions

 operator const char * () const
 Implicit return of const char*.
 
const char * C_String (void) const
 Same as std::string::c_str.
 
RakStringoperator= (const RakString &rhs)
 Assigment operators.
 
RakStringoperator+= (const RakString &rhs)
 Concatenation.
 
unsigned char operator[] (const unsigned int position) const
 Character index. Do not use to change the string however.
 
size_t Find (const char *stringToFind, size_t pos=0)
 
bool operator== (const RakString &rhs) const
 Equality.
 
bool operator!= (const RakString &rhs) const
 Inequality.
 
const char * ToLower (void)
 Change all characters to lowercase.
 
const char * ToUpper (void)
 Change all characters to uppercase.
 
void Set (const char *format,...)
 Set the value of the string.
 
RakString Assign (const char *str, size_t pos, size_t n)
 
bool IsEmpty (void) const
 Returns if the string is empty. Also, C_String() would return "".
 
size_t GetLength (void) const
 Returns the length of the string.
 
void Replace (unsigned index, unsigned count, unsigned char c)
 Replace character(s) in starting at index, for count, with c.
 
void SetChar (unsigned index, unsigned char c)
 Replace character at index with c.
 
void SetChar (unsigned index, RakNet::RakString s)
 Replace character at index with string s.
 
void Truncate (unsigned int length)
 Make sure string is no longer than length.
 
void Erase (unsigned int index, unsigned int count)
 Erase characters out of the string at index for count.
 
void TerminateAtFirstCharacter (char c)
 Set the first instance of c with a NULL terminator.
 
void TerminateAtLastCharacter (char c)
 Set the last instance of c with a NULL terminator.
 
int GetCharacterCount (char c)
 Returns how many occurances there are of c in the string.
 
void RemoveCharacter (char c)
 Remove all instances of c.
 
int StrCmp (const RakString &rhs) const
 Compare strings (case sensitive)
 
int StrNCmp (const RakString &rhs, size_t num) const
 Compare strings (case sensitive), up to num characters.
 
int StrICmp (const RakString &rhs) const
 Compare strings (not case sensitive)
 
void Clear (void)
 Clear the string.
 
void Printf (void)
 Print the string to the screen.
 
void FPrintf (FILE *fp)
 Print the string to a file.
 
bool IPAddressMatch (const char *IP)
 Does the given IP address match the IP address encoded into this string, accounting for wildcards?
 
bool ContainsNonprintableExceptSpaces (void) const
 Does the string contain non-printable characters other than spaces?
 
bool IsEmailAddress (void) const
 Is this a valid email address?
 
RakNet::RakStringURLEncode (void)
 URL Encode the string. See http://www.codeguru.com/cpp/cpp/cpp_mfc/article.php/c4029/.
 
RakNet::RakStringURLDecode (void)
 URL decode the string.
 
void SplitURI (RakNet::RakString &header, RakNet::RakString &domain, RakNet::RakString &path)
 https://servers.api.rackspacecloud.com/v1.0 to https://, servers.api.rackspacecloud.com, /v1.0
 
RakNet::RakStringSQLEscape (void)
 Scan for quote, double quote, and backslash and prepend with backslash.
 
RakNet::RakStringMakeFilePath (void)
 Fix to be a file path, ending with /.
 
void Serialize (BitStream *bs) const
 
void SerializeCompressed (BitStream *bs, uint8_t languageId=0, bool writeLanguageId=false) const
 
bool Deserialize (BitStream *bs)
 
bool DeserializeCompressed (BitStream *bs, bool readLanguageId=false)
 

Static Public Member Functions

static RakNet::RakString NonVariadic (const char *str)
 
static unsigned long ToInteger (const char *str)
 Hash the string into an unsigned int.
 
static int ReadIntFromSubstring (const char *str, size_t pos, size_t n)
 Read an integer out of a substring.
 
static RakNet::RakString FormatForPOST (const char *uri, const char *contentType, const char *body, const char *extraHeaders="")
 
static RakNet::RakString FormatForGET (const char *uri, const char *extraHeaders="")
 
static RakNet::RakString FormatForDELETE (const char *uri, const char *extraHeaders="")
 
static void FreeMemory (void)
 
static void Serialize (const char *str, BitStream *bs)
 Static version of the Serialize function.
 
static void SerializeCompressed (const char *str, BitStream *bs, uint8_t languageId=0, bool writeLanguageId=false)
 Static version of the SerializeCompressed function.
 
static bool Deserialize (char *str, BitStream *bs)
 Static version of the Deserialize() function.
 
static bool DeserializeCompressed (char *str, BitStream *bs, bool readLanguageId=false)
 Static version of the DeserializeCompressed() function.
 

Detailed Description

String class.

Has the following improvements over std::string -Reference counting: Suitable to store in lists -Variadic assignment operator -Doesn't cause linker errors

Member Function Documentation

RakString RakNet::RakString::Assign ( const char *  str,
size_t  pos,
size_t  n 
)

Sets a copy of a substring of str as the new content. The substring is the portion of str that begins at the character position pos and takes up to n characters (it takes less than n if the end of str is reached before).

Parameters
[in]strThe string to copy in
[in]posThe position on str to start the copy
[in]nHow many chars to copy
Returns
Returns the string, note that the current string is set to that value as well
bool RakNet::RakString::Deserialize ( BitStream bs)

Deserialize what was written by Serialize

Parameters
[in]bsBitstream to serialize from
Returns
true if the deserialization was successful
bool RakNet::RakString::DeserializeCompressed ( BitStream bs,
bool  readLanguageId = false 
)

Deserialize compressed string, written by SerializeCompressed

Parameters
[in]bsBitstream to serialize from
[in]readLanguageIdIf true, looks for the variable langaugeId in the data stream. Must match what was passed to SerializeCompressed
Returns
true if the deserialization was successful
Precondition
StringCompressor::AddReference must have been called to instantiate the class (Happens automatically from RakPeer::Startup())
size_t RakNet::RakString::Find ( const char *  stringToFind,
size_t  pos = 0 
)

String class find replacement Searches the string for the content specified in stringToFind and returns the position of the first occurrence in the string. Search only includes characters on or after position pos, ignoring any possible occurrences in previous locations.

Parameters
[in]stringToFindThe string to find inside of this object's string
[in]posThe position in the string to start the search
Returns
Returns the position of the first occurrence in the string.
static RakNet::RakString RakNet::RakString::FormatForDELETE ( const char *  uri,
const char *  extraHeaders = "" 
)
static

Format as a DELETE command that can be sent to a webserver

Parameters
[in]uriFor example, masterserver2.raknet.com/testServer?__gameId=comprehensivePCGame&__rowId=1
Returns
Formatted string
static RakNet::RakString RakNet::RakString::FormatForGET ( const char *  uri,
const char *  extraHeaders = "" 
)
static

Format as a GET command that can be sent to a webserver

Parameters
[in]uriFor example, masterserver2.raknet.com/testServer?__gameId=comprehensivePCGame
Returns
Formatted string
static RakNet::RakString RakNet::RakString::FormatForPOST ( const char *  uri,
const char *  contentType,
const char *  body,
const char *  extraHeaders = "" 
)
static

Format as a POST command that can be sent to a webserver

Parameters
[in]uriFor example, masterserver2.raknet.com/testServer
[in]contentTypeFor example, text/plain; charset=UTF-8
[in]bodyBody of the post
Returns
Formatted string
static void RakNet::RakString::FreeMemory ( void  )
static

RakString uses a freeList of old no-longer used strings Call this function to clear this memory on shutdown

static RakNet::RakString RakNet::RakString::NonVariadic ( const char *  str)
static

Create a RakString with a value, without doing printf style parsing Equivalent to assignment operator

static int RakNet::RakString::ReadIntFromSubstring ( const char *  str,
size_t  pos,
size_t  n 
)
static

Read an integer out of a substring.

Parameters
[in]strThe string
[in]posThe position on str where the integer starts
[in]nHow many chars to copy
void RakNet::RakString::Serialize ( BitStream bs) const

Serialize to a bitstream, uncompressed (slightly faster)

Parameters
[out]bsBitstream to serialize to
void RakNet::RakString::SerializeCompressed ( BitStream bs,
uint8_t  languageId = 0,
bool  writeLanguageId = false 
) const

Serialize to a bitstream, compressed (better bandwidth usage)

Parameters
[out]bsBitstream to serialize to
[in]languageIdlanguageId to pass to the StringCompressor class
[in]writeLanguageIdencode the languageId variable in the stream. If false, 0 is assumed, and DeserializeCompressed will not look for this variable in the stream (saves bandwidth)
Precondition
StringCompressor::AddReference must have been called to instantiate the class (Happens automatically from RakPeer::Startup())

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