yast2 |
modules/String.ycp |
String manipulation routines | |
|
|
This module has an unstable interface. |
Quote a string with 's
- Parameters:
-
var unquoted string
- Return value:
-
quoted string
- Example
-
quote("a'b") -> "a'\''b"
Unquote a string with 's (quoted with quote)
- Parameters:
-
var quoted string
- Return value:
-
unquoted string
- See
-
quote
Optional formatted text
- Parameters:
-
f s
- Return value:
-
sformat (f, s) if s is neither empty or nil, else ""
Optional parenthesized text
- Parameters:
-
s
- Return value:
-
" (Foo)" if Foo is neither empty or nil, else ""
- Parameters:
-
l a list of strings
- Return value:
-
only non-"" items
- Parameters:
-
s \n-terminated items
- Return value:
-
the items as a list, with empty lines removed
Return a pretty description of a byte count
Return a pretty description of a byte count with required precision and using KB, MB or GB as unit as appropriate.
- Parameters:
-
bytes size (e.g. free diskspace, memory size) in Bytes precision number of fraction digits in output omit_zeroes if true then do not add zeroes (usefull for memory size - 128 MB RAM looks better than 128.00 MB RAM)
- Return value:
-
formatted string
- Example
-
FormatSizeWithPrecision(4096, 2, true) -> "4 KB" FormatSizeWithPrecision(4096, 2, false) -> "4.00 KB"
Return a pretty description of a byte count
Return a pretty description of a byte count, with two fraction digits and using KB, MB or GB as unit as appropriate.
- Parameters:
-
bytes size (e.g. free diskspace) in Bytes
- Return value:
-
formatted string
- Example
-
FormatSize(23456767890) -> "223.70 MB"
Remove blanks at begin and end of input string.
- Parameters:
-
input string to be stripped
- Return value:
-
stripped string
- Example
-
CutBlanks(" any input ") -> "any input"
Remove any leading zeros
Remove any leading zeros that make tointeger inadvertently assume an octal number (e.g. "09" -> "9", "0001" -> "1", but "0" -> "0")
- Parameters:
-
input number that might contain leadig zero
- Return value:
-
that has leading zeros removed
Add spaces after the text to make it long enough
Add spaces after the text to make it long enough. If the text is longer than requested, no changes are made.
- Parameters:
-
text text to be padded length requested length
- Return value:
-
padded text
Add zeros before the text to make it long enough.
Add zeros before the text to make it long enough. If the text is longer than requested, no changes are made.
- Parameters:
-
text text to be padded length requested length
- Return value:
-
padded text
Parse string of values
- Parameters:
-
options Input string parameters Parmeter used at parsing - map with keys: "separator": - value separator (default: " \t"), "unique": - result will not contain any duplicates, first occurance of the string is stored into output (default: false), "interpret_backslash": - convert backslash sequence into one character (e.g. "\\n" => "\n") (default: true) "remove_whitespace": - remove white spaces around values (default: true),
- Return value:
-
List of strings
Remove first or every match of given regular expression from a string
(e.g. CutRegexMatch( "abcdef12ef34gh000", "[0-9]+", true ) -> "abcdefefgh", CutRegexMatch( "abcdef12ef34gh000", "[0-9]+", false ) -> "abcdefef34gh000")
- Parameters:
-
input string that might occur regex regex regular expression to search for, must not contain brackets glob flag if only first or every occuring match should be removed
- Return value:
-
that has matches removed
Function for escaping (replacing) (HTML|XML...) tags with their (HTML|XML...) meaning.
Usable to present text "as is" in RichText.
- Parameters:
-
text
- Return value:
-
escaped text
Shorthand for select (splitstring (s, separators), 0, "") Useful now that the above produces a deprecation warning.
- Parameters:
-
s string to be split separators characters which delimit components
- Return value:
-
first component or ""
- Return value:
-
the 26 uppercase ASCII letters
- Return value:
-
the 26 lowercase ASCII letters
- Return value:
-
the 52 upper and lowercase ASCII letters
- Return value:
-
0123456789
- Return value:
-
hexadecimal digits: 0123456789ABCDEFabcdef
- Return value:
-
the 52 upper and lowercase ASCII letters and digits
- Return value:
-
the ASCII printable non-blank non-alphanumeric characters
- Return value:
-
printable ASCII charcters except whitespace
- Return value:
-
ASCII whitespace
- Return value:
-
printable ASCII characters including whitespace
Characters valid in a filename (not pathname). Naturally "/" is disallowed. Otherwise, the graphical ASCII characters are allowed.
- Return value:
-
for ValidChars
Function creates text table without using HTML tags. (Useful for commandline) Undefined option uses the default one.
- Parameters:
-
header items options
- Return value:
-
table Header: [ "Id", "Configuration", "Device" ] Items: [ [ "1", "aaa", "Samsung Calex" ], [ "2", "bbb", "Trivial Trinitron" ] ] Possible Options: horizontal_padding (for columns), table_left_padding (for table)
Function returns underlined text header without using HTML tags. (Useful for commandline)
- Parameters:
-
header_line left_padding
- Return value:
-
underlined header line
Get metadata lines from input string
- Parameters:
-
input Input string - complete comment of a sysconfig variable
- Return value:
-
Metadata lines in list
Get comment without metadata
- Parameters:
-
input Input string - complete comment of a sysconfig variable
- Return value:
-
Comment used as variable description
Parse metadata from a sysconfig comment
- Parameters:
-
comment comment of a sysconfig variable (single line or multiline string)
- Return value:
-
parsed metadata
Replace substring in a string. All substrings source are replaced by string target.
- Parameters:
-
s input string source the string which will be replaced target the new string which is used instead of source
- Return value:
-
result
Returns text wrapped at defined margin. Very useful for translated strings used for pop-up windows or dialogs where you can't know the width. It controls the maximum width of the string so the text should allways fit into the minimal ncurses window. If you expect some long words, such us URLs or words with a hyphen inside, you can also set the additional split-characters to "/-". Then the function can wrap the word also after these characters. This function description was wrapped using the function String::WrapAt().
- Parameters:
-
text width split_string
- Return value:
-
wrapped string
- Example
-
String::WrapAt("Some very long text",30,"/-");
Make a random base-36 number. srandom should be called beforehand.
- Parameters:
-
len string length
- Return value:
-
random string of 0-9 and a-z