My Project
Static Public Member Functions | List of all members
ParaScripting::ParaMisc Class Reference

Contains miscellaneous functions. More...

#include <ParaScriptingMisc.h>

Static Public Member Functions

static int GetUnicodeCharNum (const char *str)
 get the number of characters in str. More...
 
static std::string UniSubString (const char *str, int nFrom, int nTo)
 same as LUA string.sub(), except that the index is character. More...
 
static std::string UTF8ToUTF16 (const std::string &utf8)
 Converts utf8 string to utf16 string. More...
 
static std::string UTF16ToUTF8 (const std::string &utf16)
 Converts utf16 string to utf8 string. More...
 
static std::string SimpleEncode (const std::string &source)
 encode a string using really simple algorithm. More...
 
static std::string SimpleDecode (const std::string &source)
 decode a string using really simple algorithm. More...
 
static string md5 (const string &source)
 convert the md5 of the input source string. More...
 
static string md5_ (const string &source, bool bBinary)
 
static string sha1 (const string &source)
 convert the sha1 of the input source string. More...
 
static string sha1_ (const string &source, bool bBinary)
 
static string base64 (const string &source)
 convert the base64 of the input source string. More...
 
static string unbase64 (const string &source)
 return the unbase64 of the input source string. More...
 
static long RandomLong (const object &seedTable)
 Generating [-MAX, MAX] long integer. More...
 
static double RandomDouble (const object &seedTable)
 generating [0,1] double value
 
static const std::string & EncodingConvert (const std::string &srcEncoding, const std::string &dstEncoding, const std::string &bytes)
 Converts an entire byte array from one encoding to another. More...
 
static bool CopyTextToClipboard (const char *text)
 copy text to clipboard. More...
 
static const char * GetTextFromClipboard ()
 get text from clipboard. More...
 

Detailed Description

Contains miscellaneous functions.

Member Function Documentation

§ base64()

std::string ParaScripting::ParaMisc::base64 ( const string &  source)
static

convert the base64 of the input source string.

§ CopyTextToClipboard()

bool ParaScripting::ParaMisc::CopyTextToClipboard ( const char *  text)
static

copy text to clipboard.

Input is ANSI code page

§ EncodingConvert()

const std::string & ParaScripting::ParaMisc::EncodingConvert ( const std::string &  srcEncoding,
const std::string &  dstEncoding,
const std::string &  bytes 
)
static

Converts an entire byte array from one encoding to another.

Parameters
srcEncodingany encoding name. If nil or "", it is the default coding in NPL. see Encoding.GetEncoding(). Below are some commonly used field | Code Page | Name | | 950 | big5 | | 936 | gb2312 | | 65001 | utf-8 | | | utf-16 | | 65005 | utf-32 | There is one special code name called "HTML", which contains HTML special characters in ascii code page. This is usually true for most "iso8859-15" encoding in western worlds. It just writes the unicode number+XXXX in ascii character "&#XXXX;" where & is optional.
dstEncodingsave as above. If nil or "", it will be converted to default coding in NPL. : the source bytes. e.g. The most common use of this function is to create HTML special character to NPL string, like below local text = ParaMisc.EncodingConvert("HTML", "", "Chinese characters: &#24320;&#21457;") log(text);

§ GetTextFromClipboard()

const char * ParaScripting::ParaMisc::GetTextFromClipboard ( )
static

get text from clipboard.

text is converted to ANSI code page when returned.

§ GetUnicodeCharNum()

int ParaScripting::ParaMisc::GetUnicodeCharNum ( const char *  str)
static

get the number of characters in str.

Str is assumed to be in ANSI code page. it is converted to Unicode and return the character count.

§ md5()

string ParaScripting::ParaMisc::md5 ( const string &  source)
static

convert the md5 of the input source string.

§ RandomLong()

long ParaScripting::ParaMisc::RandomLong ( const object seedTable)
static

Generating [-MAX, MAX] long integer.

Parameters
seedTablenil or a table containing {_seed=integer} when the function returned the seedTable._seed will be modified.

§ sha1()

std::string ParaScripting::ParaMisc::sha1 ( const string &  source)
static

convert the sha1 of the input source string.

§ SimpleDecode()

std::string ParaScripting::ParaMisc::SimpleDecode ( const std::string &  source)
static

decode a string using really simple algorithm.

str = SimpleDecode(SimpleEncode(str))

Returns
: it may return NULL if input invalid

§ SimpleEncode()

std::string ParaScripting::ParaMisc::SimpleEncode ( const std::string &  source)
static

encode a string using really simple algorithm.

it just makes the source ineligible. It is still not immune to crackers. str = SimpleDecode(SimpleEncode(str))

Returns
: it may return NULL if input invalid

§ unbase64()

std::string ParaScripting::ParaMisc::unbase64 ( const string &  source)
static

return the unbase64 of the input source string.

§ UniSubString()

std::string ParaScripting::ParaMisc::UniSubString ( const char *  str,
int  nFrom,
int  nTo 
)
static

same as LUA string.sub(), except that the index is character.

get a sub string of a ANSI Code page string. However, the index are unicode characters.

Parameters
strthe string to use
nFromcharacter index beginning from 1.

§ UTF16ToUTF8()

std::string ParaScripting::ParaMisc::UTF16ToUTF8 ( const std::string &  utf16)
static

Converts utf16 string to utf8 string.

Parameters
utf16The utf16 string to be converted
Returns
The output utf8 string

§ UTF8ToUTF16()

std::string ParaScripting::ParaMisc::UTF8ToUTF16 ( const std::string &  utf8)
static

Converts utf8 string to utf16 string.

Parameters
utf8The utf8 string to be converted
Returns
outUtf16 string

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