YCPBuiltinString.cc File Reference

#include <unistd.h>
#include <ctype.h>
#include <stdio.h>
#include <regex.h>
#include <libintl.h>
#include <iostream>
#include <string>
#include "ycp/YCPBuiltinString.h"
#include "ycp/YCPString.h"
#include "ycp/YCPInteger.h"
#include "ycp/YCPPath.h"
#include "ycp/YCPSymbol.h"
#include "ycp/YCPBoolean.h"
#include "ycp/YCPVoid.h"
#include "ycp/y2log.h"
#include "y2string.h"
#include "y2crypt.h"
#include "ycp/StaticDeclaration.h"

Classes

struct  REG_RET

Defines

#define _XOPEN_SOURCE
#define _GNU_SOURCE
#define ERR_MAX   80
#define SUB_MAX   10

Typedefs

typedef REG_RET Reg_Ret

Functions

static YCPValue s_size (const YCPString &s)
 Returns the number of characters of the string s.
static YCPValue s_plus1 (const YCPString &s1, const YCPString &s2)
static YCPValue s_plus2 (const YCPString &s1, const YCPInteger &i2)
 String and integer Concatenation.
static YCPValue s_plus3 (const YCPString &s1, const YCPPath &p2)
 String and path Concatenation Returns concatenation of s1 and p2 after transforming p2 to a string.
static YCPValue s_plus4 (const YCPString &s1, const YCPSymbol &s2)
 String and symbol Concatenation.
static YCPValue s_issubstring (const YCPString &target, const YCPString &sub)
 searches for a specific string within another string
static YCPValue s_tohexstring (const YCPInteger &i)
 Converts an integer to a hexadecimal string.
static YCPValue s_substring1 (const YCPString &s, const YCPInteger &i1)
 Returns part of a string.
static YCPValue s_substring2 (const YCPString &s, const YCPInteger &i1, const YCPInteger &i2)
 Extracts a substring.
static YCPValue s_search (const YCPString &s1, const YCPString &s2)
 Returns position of a substring.
static YCPValue s_find (const YCPString &s1, const YCPString &s2)
 Returns position of a substring.
static YCPValue s_tolower (const YCPString &s)
 Makes a string lowercase.
static YCPValue s_toupper (const YCPString &s)
 Makes a string uppercase.
static YCPValue s_toascii (const YCPString &s)
 Returns characters below 0x7F included in STRING.
static YCPValue s_removechars (const YCPString &s, YCPString &r)
 Removes all characters from a string.
static YCPValue s_filterchars (const YCPString &s, const YCPString &i)
 Filters characters out of a String.
static YCPValue s_mergestring (const YCPList &l, const YCPString &s)
 Joins list elements with a string.
static YCPValue s_findfirstnotof (const YCPString &s1, const YCPString &s2)
 Searches string for the first non matching chars.
static YCPValue s_findfirstof (const YCPString &s1, const YCPString &s2)
 Finds position of the first matching characters in string.
static YCPValue s_findlastof (const YCPString &s1, const YCPString &s2)
 Searches string for the last match The `findlastof' function searches string for the last match of any character stored in chars and returns its position.
static YCPValue s_findlastnotof (const YCPString &s1, const YCPString &s2)
 Searches the last element of string that doesn't match.
Reg_Ret solve_regular_expression (const char *input, const char *pattern, const char *result)
static YCPValue s_regexpmatch (const YCPString &i, const YCPString &p)
 Searches a string for a POSIX Extended Regular Expression match.
static YCPValue s_regexppos (const YCPString &inp, const YCPString &pat)
 Returns a pair with position and length of the first match.
static YCPValue s_regexpsub (const YCPString &i, const YCPString &p, const YCPString &m)
 Regex Substitution.
static YCPValue s_regexptokenize (const YCPString &i, const YCPString &p)
 Regex tokenize.
static YCPValue s_tostring (const YCPValue &v)
 Converts a value to a string.
static YCPValue s_timestring (const YCPString &fmt, const YCPInteger &time, const YCPBoolean &utc_flag)
 Returns time string Combination of standard libc functions gmtime or localtime and strftime.
static YCPValue s_crypt (const YCPString &s)
 Encrypts a string Encrypts the string UNENCRYPTED using the standard password encryption provided by the system.
static YCPValue s_cryptmd5 (const YCPString &s)
 Encrypts a string using md5 Encrypts the string UNENCRYPTED using MD5 password encryption.
static YCPValue s_cryptbigcrypt (const YCPString &original)
 Encrypts a string using bigcrypt Encrypts the string UNENCRYPTED using bigcrypt password encryption. The password is not truncated.
static YCPValue s_cryptblowfish (const YCPString &original)
 Encrypts a string with blowfish Encrypts the string UNENCRYPTED using blowfish password encryption. The password is not truncated.
static YCPValue s_dgettext (const YCPString &domain, const YCPString &text)
 Translates the text using the given text domain Translates the text using the given text domain into the current language.
static YCPValue s_dngettext (const YCPString &domain, const YCPString &singular, const YCPString &plural, const YCPInteger &count)
 Translates the text using a locale-aware plural form handling Translates the text using a locale-aware plural form handling using the given textdomain.

Variables

StaticDeclaration static_declarations

Define Documentation

#define _GNU_SOURCE
 

#define _XOPEN_SOURCE
 

#define ERR_MAX   80
 

#define SUB_MAX   10
 


Typedef Documentation

typedef struct REG_RET Reg_Ret
 


Function Documentation

static YCPValue s_crypt const YCPString s  )  [static]
 

Encrypts a string Encrypts the string UNENCRYPTED using the standard password encryption provided by the system.

crypt

Parameters:
string UNENCRYPTED
Returns:
string
crypt ("readable") -> "Y2PEyAiaeaFy6"

static YCPValue s_cryptbigcrypt const YCPString original  )  [static]
 

Encrypts a string using bigcrypt Encrypts the string UNENCRYPTED using bigcrypt password encryption. The password is not truncated.

cryptbigcrypt

Parameters:
string UNENCRYPTED
Returns:
string
cryptbigcrypt ("readable") -> "d4brTQmcVbtNg"

static YCPValue s_cryptblowfish const YCPString original  )  [static]
 

Encrypts a string with blowfish Encrypts the string UNENCRYPTED using blowfish password encryption. The password is not truncated.

cryptblowfish

Parameters:
string UNENCRYPTED
Returns:
string cryptblowfish ("readable") -> "$2a$05$B3lAUExB.Bqpy8Pq0TpZt.s7EydrmxJRuhOZR04YG01ptwOUR147C"

static YCPValue s_cryptmd5 const YCPString s  )  [static]
 

Encrypts a string using md5 Encrypts the string UNENCRYPTED using MD5 password encryption.

cryptmd5

Parameters:
string UNENCRYPTED
Returns:
string
cryptmd5 ("readable") -> "$1$BBtzrzzz$zc2vEB7XnA3Iq7pOgDsxD0"

static YCPValue s_dgettext const YCPString domain,
const YCPString text
[static]
 

Translates the text using the given text domain Translates the text using the given text domain into the current language.

_(string text) -> string Translates the text using the current textdomain.

Example

 _("File") -> "Soubor"
 

dgettext

This is a special case builtin not intended for general use. See _() instead.

Parameters:
string textdomain
string text
Returns:
string dgettext ("base", "No") -> "Nie"

static YCPValue s_dngettext const YCPString domain,
const YCPString singular,
const YCPString plural,
const YCPInteger count
[static]
 

Translates the text using a locale-aware plural form handling Translates the text using a locale-aware plural form handling using the given textdomain.

_(string singular, string plural, integer value) -> string Translates the text using a locale-aware plural form handling and the current textdomain. The chosen form of the translation depends on the value.

Example

 _("%1 File", "%1 Files", 2) -> "%1 soubory"
 

dngettext

The chosen form of the translation depend on the value.

This is a special case builtin not intended for general use. See _() instead.

Parameters:
string textdomain
string singular
string plural
integer value
Returns:
string
dngettext ("base", "%1 File", "%1 Files", 2) -> "%1 soubory"

static YCPValue s_filterchars const YCPString s,
const YCPString i
[static]
 

Filters characters out of a String.

filterchars

Parameters:
string STRING
string CHARS chars to be included
Returns:
string
Returns a string that results from string STRING by removing all characters that do not occur in CHARS.

See also:
deletechars filterchars ("a", "abcdefghijklmnopqrstuvwxyz") -> "ac" filterchars ("abc","cde") -> "c"

static YCPValue s_find const YCPString s1,
const YCPString s2
[static]
 

Returns position of a substring.

find

Parameters:
string STRING1 String
string STRING2 Substring
Returns:
integer OFFSET If substring is not found find returns `-1'.

The find function searches string for the first occurency of a specified substring (possibly a single character) and returns its starting position.

Returns the first position in STRING1 where the string STRING2 is contained in STRING1. OFFSET starts with 0.

Deprecated:
Use search() instead
See also:
findfirstof

findfirstnotof

search find ("abcdefghi", "efg") -> 4 find ("aaaaa", "z") -> -1

static YCPValue s_findfirstnotof const YCPString s1,
const YCPString s2
[static]
 

Searches string for the first non matching chars.

findfirstnotof

Parameters:
string STRING
string CHARS
The findfirstnotof function searches the first element of string that doesn't match any character stored in chars and returns its position.

Returns:
integer the position of the first character in STRING that is not contained in CHARS.
See also:
findfirstof

find findfirstnotof ("abcdefghi", "abcefghi") -> 3 findfirstnotof ("aaaaa", "a") -> nil

static YCPValue s_findfirstof const YCPString s1,
const YCPString s2
[static]
 

Finds position of the first matching characters in string.

findfirstof

Parameters:
string STRING
string CHARS Characters to find
The findfirstof function searches string for the first match of any character stored in chars and returns its position.

If no match is found findfirstof returns `nil'.

Returns:
integer the position of the first character in STRING that is contained in CHARS.
See also:
findfirstnotof

find findfirstof ("abcdefghi", "cxdv") -> 2 findfirstof ("aaaaa", "z") -> nil

static YCPValue s_findlastnotof const YCPString s1,
const YCPString s2
[static]
 

Searches the last element of string that doesn't match.

findlastnotof

Parameters:
string STRING
string CHARS Characters The `findlastnotof' function searches the last element of string that doesn't match any character stored in chars and returns its position.
If no match is found the function returns `nil'.

Returns:
integer The position of the last character in STRING that is NOT contained in CHARS.
See also:
findfirstnotof findlastnotof( "abcdefghi", "abcefghi" ) -> 3 ('d') findlastnotof("aaaaa", "a") -> nil

static YCPValue s_findlastof const YCPString s1,
const YCPString s2
[static]
 

Searches string for the last match The `findlastof' function searches string for the last match of any character stored in chars and returns its position.

findlastof

Parameters:
string STRING String
string CHARS Characters to find
Returns:
integer the position of the last character in STRING that is contained in CHARS.
See also:
findfirstof findlastof ("abcdecfghi", "cxdv") -> 5 findlastof ("aaaaa", "z") -> nil

static YCPValue s_issubstring const YCPString target,
const YCPString sub
[static]
 

searches for a specific string within another string

issubstring

Parameters:
string s String to be searched
string substring Pattern to be searched for
Returns:
boolean Return true, if substring is a substring of s.
issubstring ("some text", "tex") -> true

static YCPValue s_mergestring const YCPList l,
const YCPString s
[static]
 

Joins list elements with a string.

mergestring

Parameters:
list<string> PIECES A List of strings
string GLUE
Returns:
string
Returns a string containing a string representation of all the list elements in the same order, with the glue string between each element.

List elements which are not of type strings are ignored.

See also:
splitstring
mergestring (["", "abc", "dev", "ghi"], "/") -> "/abc/dev/ghi" mergestring (["abc", "dev", "ghi", ""], "/") -> "abc/dev/ghi/" mergestring ([1, "a", 3], ".") -> "a" mergestring (["1", "a", "3"], ".") -> "a" mergestring ([], ".") -> "1.a.3" mergestring (["abc", "dev", "ghi"], "") -> "abcdevghi" mergestring (["abc", "dev", "ghi"], "123") -> "abc123dev123ghi"

static YCPValue s_plus1 const YCPString s1,
const YCPString s2
[static]
 

string s1 + string s2 -> string Returns concatenation of s1 and s2.

Example:

 "YaST" + "2" -> "YaST2"
 

static YCPValue s_plus2 const YCPString s1,
const YCPInteger i2
[static]
 

String and integer Concatenation.

string s1 + integer i2 -> string

Returns concatenation of s1 and i2 after transforming i2 to a string.

Example:

"YaST" + 2 -> "YaST2"

static YCPValue s_plus3 const YCPString s1,
const YCPPath p2
[static]
 

String and path Concatenation Returns concatenation of s1 and p2 after transforming p2 to a string.

string s1 + path p2 -> string

Example: "YaST" + .two -> "YaST.two"

static YCPValue s_plus4 const YCPString s1,
const YCPSymbol s2
[static]
 

String and symbol Concatenation.

string s1 + symbol s2 -> string

Returns concatenation of s1 and s2 after transforming s2 to a string AND stripping the leading backquote.

Example: "YaST" + `two -> "YaSTtwo"

static YCPValue s_regexpmatch const YCPString i,
const YCPString p
[static]
 

Searches a string for a POSIX Extended Regular Expression match.

regexpmatch

Parameters:
string INPUT
string PATTERN
Returns:
boolean
See also:
regex(7)
regexpmatch ("aaabbbccc", "ab") -> true regexpmatch ("aaabbbccc", "^ab") -> false regexpmatch ("aaabbbccc", "ab+c") -> true regexpmatch ("aaa(bbb)ccc", "\\(.*\\)") -> true

static YCPValue s_regexppos const YCPString inp,
const YCPString pat
[static]
 

Returns a pair with position and length of the first match.

regexppos

Parameters:
string INPUT
string PATTERN
Returns:
list
If no match is found it returns an empty list.

See also:
regex(7).
regexppos ("abcd012efgh345", "[0-9]+") -> [4, 3] ("aaabbb", "[0-9]+") -> []

static YCPValue s_regexpsub const YCPString i,
const YCPString p,
const YCPString m
[static]
 

Regex Substitution.

regexpsub

Parameters:
string INPUT
string PATTERN
string OUTPUT
Returns:
string
Searches a string for a POSIX Extended Regular Expression match and returns OUTPUT with the matched subexpressions substituted or nil if no match was found.

See also:
regex(7)
regexpsub ("aaabbb", "(.*ab)", "s_\\1_e") -> "s_aaab_e" regexpsub ("aaabbb", "(.*ba)", "s_\\1_e") -> nil

static YCPValue s_regexptokenize const YCPString i,
const YCPString p
[static]
 

Regex tokenize.

regexptokenize

Parameters:
string INPUT
string PATTERN
Returns:
list
See also:
regex(7). Searches a string for a POSIX Extended Regular Expression match and returns a list of the matched subexpressions
If the pattern does not match, the list is empty. Otherwise the list contains then matchted subexpressions for each pair of parenthesize in pattern.

If the pattern is invalid, 'nil' is returned.

Examples: // e == [ "aaabbB" ] list e = regexptokenize ("aaabbBb", "(.*[A-Z]).*");

// h == [ "aaab", "bb" ] list h = regexptokenize ("aaabbb", "(.*ab)(.*)");

// h == [] list h = regexptokenize ("aaabbb", "(.*ba).*");

// h == nil list h = regexptokenize ("aaabbb", "(.*ba).*(");

static YCPValue s_removechars const YCPString s,
YCPString r
[static]
 

Removes all characters from a string.

deletechars

Parameters:
string STRING
string REMOVE Characters to be removed from STRING
Returns:
string
Returns a string that results from string STRING by removing all characters that occur in string REMOVE.

See also:
filterchars deletechars ("a", "abcdefghijklmnopqrstuvwxyz") -> "" deletechars ("abc","cde") -> "ab"

static YCPValue s_search const YCPString s1,
const YCPString s2
[static]
 

Returns position of a substring.

search

Parameters:
string STRING1 String
string STRING2 Substring
Returns:
integer OFFSET If substring is not found find returns `nil'.

The search function searches string for the first occurency of a specified substring (possibly a single character) and returns its starting position.

Returns the first position in STRING1 where the string STRING2 is contained in STRING1. OFFSET starts with 0.

See also:
findfirstof

findfirstnotof

find search ("abcdefghi", "efg") -> 4 search ("aaaaa", "z") -> nil

static YCPValue s_size const YCPString s  )  [static]
 

Returns the number of characters of the string s.

size

Parameters:
string s String
Returns:
integer Size of string s
Notice, that size(nil) -> nil

size("size") -> 4

static YCPValue s_substring1 const YCPString s,
const YCPInteger i1
[static]
 

Returns part of a string.

substring substring_1

Parameters:
string STRING Original String
integer OFFSET Start position integer LENGTH Length of new string
Returns:
string
Returns the portion of STRING specified by the OFFSET and LENGHT parameters. OFFSET starts with 0.

substring ("some text", 5) -> "text" substring ("some text", 42) -> "" substring ("some text", 5, 2) -> "te" substring ("some text", 42, 2) -> "" substring("123456789", 2, 3) -> "345"

static YCPValue s_substring2 const YCPString s,
const YCPInteger i1,
const YCPInteger i2
[static]
 

Extracts a substring.

substring substring_2

Extracts a substring of the string STRING, starting at OFFSET after the first one with length of at most LENGTH. OFFSET starts with 0.

Parameters:
string STRING
integer OFFSET
integer LENGTH
Returns:
string substring ("some text", 5, 2) -> "te" substring ("some text", 42, 2) -> "" substring("123456789", 2, 3) -> "345"

static YCPValue s_timestring const YCPString fmt,
const YCPInteger time,
const YCPBoolean utc_flag
[static]
 

Returns time string Combination of standard libc functions gmtime or localtime and strftime.

timestring

Parameters:
string FORMAT
integer TIME
boolean UTC
Returns:
string
timestring ("%F %T %Z", time (), false) -> "2004-08-24 14:55:05 CEST"

static YCPValue s_toascii const YCPString s  )  [static]
 

Returns characters below 0x7F included in STRING.

toascii

Parameters:
string STRING
Returns:
string
Returns a string that results from string STRING by copying each character that is below 0x7F (127).

toascii ("aBë") -> "aB" toascii ("123+-abcABCöëä") -> "123+-abcABC"

static YCPValue s_tohexstring const YCPInteger i  )  [static]
 

Converts an integer to a hexadecimal string.

tohexstring

Parameters:
integer number Number
Returns:
string number in Hex

tohexstring (31) -> "0x1f"

static YCPValue s_tolower const YCPString s  )  [static]
 

Makes a string lowercase.

tolower

Parameters:
string s String
Returns:
string String in lower case
Returns string with all alphabetic characters converted to lowercase. Notice: national characters are left unchanged.

tolower ("aBcDeF") -> "abcdef" tolower ("ABCÁÄÖČ") -> "abcÁÄÖČ"

static YCPValue s_tostring const YCPValue v  )  [static]
 

Converts a value to a string.

tostring

Parameters:
any VALUE
Returns:
string
tostring(.path) -> ".path" tostring([1,2,3]) -> "[1, 2, 3]" tostring($[1:1,2:2,3:3]) -> "$[1:1, 2:2, 3:3]" tostring(`Empty()) -> "`Empty ()"

static YCPValue s_toupper const YCPString s  )  [static]
 

Makes a string uppercase.

toupper

Returns string with all alphabetic characters converted to uppercase.

See also:
toupper tolower ("aBcDeF") -> "ABCDEF" toupper ("abcáäöč") -> "ABCáäöč"

Reg_Ret solve_regular_expression const char *  input,
const char *  pattern,
const char *  result
 


Variable Documentation

StaticDeclaration static_declarations
 


Generated on Fri Jun 16 18:07:45 2006 for yast2-core by  doxygen 1.4.6