Index  |  Related pages  |  Classes  |  Functions  |  Entities  |  Function Sets  |  Groups

Function set core_string_functions

Functions manipulating strings


Function list

strAllTrim Removes white spaces at both the beginning and the end of the string.
strBack Returns the last part of a string.
strBackFind Finds a substring bakwards.
strBuffer Pre-allocates an empty string.
strCmpIgnoreCase Performs a lexicographic comparation of two strings, ignoring character case.
strFind Finds a substring.
strFromMemBuf Convets a MemBuf to a string.
strFront Returns the first part of a string.
strFrontTrim Removes white spaces from the front of the string.
strLower Returns a lowercase version of the given string.
strMerge Merges an array of strings into a string.
strReplace Replaces the all the occurrences of a substring with another one.
strReplicate Returns a new string that is created by replicating the original one.
strSplit Subdivides a string in an array of substrings given a token substring.
strSplitTrimmed Subdivides a string in an array of substrings given a token substring.
strToMemBuf Convets a string to a membuf
strTrim Removes the white spaces at the end of a string.
strUpper Returns an upper case version of the string.
strWildcardMatch Perform an old-style file-like jolly-based wildcard match.

Functions

strAllTrim()

Removes white spaces at both the beginning and the end of the string.

strAllTrim( string, [trimSet] )
string

The string to be trimmed.

trimSet

A set of characters that must be removed.

Returns:

The trimmed substring.

A new string, which is a copy of the original one with all characters in trimSet at the beginning and at the end of the string removed, is returned. If trimSet is not supplied, it defaults to space, tabulation characters, new lines and carriage returns. The original string is unmodified.

strBack()

Returns the last part of a string.

strBack( string, count )
string

The string from which to get the last characters.

count

Number of characters to take.

Returns:

The substring.

Returns the last count characters in the string. strBack( str, 1 ) would give the last character in the string, while strBack( str, 2 ) would give the last two characters, in the same order they are in the string (so, the second-last and then the last).

If count is zero, an empty string is returned.

If count is less than 0 or greater than the size of the string, an error is raised.

strBackFind()

Finds a substring bakwards.

strBackFind( string, needle, [start], [end] )
string

String where the search will take place.

needle

Substring to search for.

start

Optional position from which to start the search in string.

end

Optional position at which to end the search in string.

Returns:

The position where the substring is found, or -1.

Works exactly as strFind, except for the fact that the last match in the string (or in the specified interval) is returned.

strBuffer()

Pre-allocates an empty string.

strBuffer( size )
size

Size of the pre-allocated string.

Returns:

The new string.

The returned string is an empty string, and equals to "". However, the required size is pre-allocated, and addition to this string (i.e. += operators) takes place in a fraction of the time otherwise required, up tho the filling of the pre-allocated buffer. Also, this string can be fed into file functions, the pre-allocation size being used as the input read size.

strCmpIgnoreCase()

Performs a lexicographic comparation of two strings, ignoring character case.

strCmpIgnoreCase( string1, string2 )
string1

First string to be compared.

string2

Second string to be compared.

Returns:

-1, 0 or 1.

The two strings are compared ignoring the case of latin characters contained in the strings.

If the first string is greater than the second, the function returns -1. If it's smaller, it returns 1. If the two strings are the same, ignoring the case of the characters, 0 is returned.

strFind()

Finds a substring.

strFind( string, needle, [start], [end] )
string

String where the search will take place.

needle

Substring to search for.

start

Optional position from which to start the search in string.

end

Optional position at which to end the search in string.

Returns:

The position where the substring is found, or -1.

Returns the index in string were needle begins, or -1 if not present. Giving a start parameter will cause the search to start from the given position up to the end of the string; if a match can be made at start position, then the the returned value will be the same as start, so when repeating searches in a string for all the possible matches, repeat until the result is -1 by adding one to the returned value and using it as start position for the next search.

If an end position is given, it is used as upper limit for the search, so that the search is in the interval [start, end-1].

strFromMemBuf()

Convets a MemBuf to a string.

strFromMemBuf( membuf )
membuf

A MemBuf that will be converted to a string.

Returns:

The resulting string.

This string takes each element of the membuf and converts it into a character in the final string. The contents of the buffer are not transcoded. It is appropriate to say that this function considers each element in the MemBuf as an Unicode value for the character in the final string.

To create a string from a buffer that may come from an encoded source (i.e. a file), use directly Transcode functions.

strFront()

Returns the first part of a string.

strFront( string, count )
string

The string from which to get the first characters.

count

Number of characters to take.

Returns:

The substring.

The string returned will contain the first count characters from the given string. If zero is given, an empty string is returned. If count is the same as the string length, a copy of the string is returned. If the size of the source string is less than the required count, an error is raised.

strFrontTrim()

Removes white spaces from the front of the string.

strFrontTrim( string, [trimSet] )
string

The string to be trimmed.

trimSet

A set of characters that must be removed.

Returns:

The trimmed substring.

A new string, which is a copy of the original one with all characters in trimSet at the beginning of the string removed, is returned. If trimSet is not supplied, it defaults to space, tabulation characters, new lines and carriage returns. The original string is unmodified.

strLower()

Returns a lowercase version of the given string.

strLower( string )
string

String that must be uppercased.

Returns:

The lowercased string.

All the Latin characters in the string are turned lowercase. Other characters are left untouched.

strMerge()

Merges an array of strings into a string.

strMerge( array, [mergeStr], [count] )
array

An array of strings to be merged.

mergeStr

A string placed between each merge.

count

Maximum count of merges.

Returns:

The merged string.

The function will return a new string containing the concatenation of the strings inside the array parameter. If the array is empty, an empty string is returned. If a mergeStr parameter is given, it is added to each pair of string merged; mergeStr is never added at the end of the new string. A count parameter may be specified to limit the number of elements merged in the array.

The function may be used in this way:

    a = strMerge( [ “a”, “string”, “of”, “words” ], “ “ )
    printl( a ) // prints “a string of words”

If an element of the array is not a string, an error is raised.

strReplace()

Replaces the all the occurrences of a substring with another one.

strReplace( string, substr, repstr, [start], [end] )
string

The string where the replace will take place.

substr

The substring that will be replaced.

repstr

The string that will take the place of substr.

start

Optional start position in the string.

end

Optional end position in the string.

Returns:

A copy of the string with the occourences of the searched substring replaced.

This is a flexible function that allows to alter a string by changing all the occurrences of a substring into another one. If the start parameter is given, the search and replacement will take place only starting at the specified position up to the end of the string, and if the end parameter is also provided, the search will take place in the interval [start, end-1].

strReplicate()

Returns a new string that is created by replicating the original one.

strReplicate( string, times )
string

The string to be replicaeted.

times

Number of times the string must be replicated.

Returns:

The new string.

A nice shortcut. Also, this function performs the work efficiently, preallocating the needed space in one shot and avoiding the need to grow the string while replicating the original value.

strSplit()

Subdivides a string in an array of substrings given a token substring.

strSplit( string, token, [count] )
string

The string that must be splitted

token

The token by which the string should be splitted.

count

Optional maximum split count.

Returns:

An array of strings containing the splitted string.

This function returns an array of strings extracted from the given parameter. The array is filled with strings extracted from the first parameter, by dividing it based on the occurrences of the token substring. A count parameter may be provided to limit the splitting, so to take into consideration only the first relevant tokens. Adjacent matching tokens will cause the returned array to contains empty strings. If no matches are possible, the returned array contains at worst a single element containing a copy of the whole string passed as a parameter.

In example, the following may be useful to parse a INI file where keys are separated from values by “=” signs:

    key, value = strSplit( string, “=”, 2 )

This code would return an array of 2 items at maximum; if no “=” signs are found in string, the above code would throw an error because of unpacking size, a thing that may be desirable in a parsing code. If there are more than one “=” in the string, only the first starting from left is considered, while the others are returned in the second item, unparsed.

strSplitTrimmed()

Subdivides a string in an array of substrings given a token substring.

strSplitTrimmed( string, token, [count] )
string

The string that must be splitted

token

The token by which the string should be splitted.

count

Optional maximum split count.

Returns:

An array of strings containing the splitted string.

This function returns an array of strings extracted from the given parameter. The array is filled with strings extracted from the first parameter, by dividing it based on the occurrences of the token substring. A count parameter may be provided to limit the splitting, so to take into consideration only the first relevant tokens. Adjacent matching tokens will cause the returned array to contains empty strings. If no matches are possible, the returned array contains at worst a single element containing a copy of the whole string passed as a parameter.

With respect to strSplit, this version also performs automatic (and optimized) trimming of whitespaces from all the splitted strings.

strToMemBuf()

Convets a string to a membuf

strToMemBuf( string, [wordWidth] )
string

String to be converted in a membuf.

wordWidth

The memory buffer word width (defaults to string character size).

Returns:

The resulting membuf.

This function creates a membuf from a string. The resulting membuf has the same word width of the original string, which may be 1, 2 or 4 byte wide depending on the size needed to store its contents. It is possible to specify a different word width; in that case the function will be much less efficient (each character must be copied).

If wordWidth is set to zero, the resulting memory buffer will have 1 byte long elements, but the content of the string will be copied as-is, bytewise, regardless of its character size.

strTrim()

Removes the white spaces at the end of a string.

strTrim( string, [trimSet] )
string

The string to be trimmed.

trimSet

A set of characters that must be removed.

Returns:

The trimmed substring.

A new string, which is a copy of the original one with all characters in trimSet at the end of the string removed, is returned. If trimSet is not supplied, it defaults to space, tabulation characters, new lines and carriage returns. The original string is unmodified.

strUpper()

Returns an upper case version of the string.

strUpper( string )
string

String that must be uppercased.

Returns:

The uppercased string.

All the Latin characters in the string are turned uppercase. Other characters are left untouched.

strWildcardMatch()

Perform an old-style file-like jolly-based wildcard match.

strWildcardMatch( wildcard, string, [ignoreCase] )
wildcard

A wildcard, possibly but not necessarily including a jolly character.

string

String that must match the wildcard.

ignoreCase

If true, the latin 26 base letters case is ignored in matches.

Returns:

True if the string matches, false otherwise.

This function matches a wildcard that may contain jolly “*” or “?” characters against a string, eventually ignoring the case of the characters. This is a practical function to match file names against given patterns. A “?” in the wildcard represents any single character, while a “*” represents an arbitrary sequence of characters.

The wildcard must match completely the given string for the function to return true.

In example:


Index  |  Related pages  |  Classes  |  Functions  |  Entities  |  Function Sets  |  Groups
Made with Faldoc 1.0.0