YaST2 Developers Documentation: Unknown YCP Module

Unknown YCP Module

This module has an unstable interface.

Global Functions

Local Functions

Info:

File: modules/String.ycp Package: yast2 Summary: String manipulation routines Authors: Michal Svec

global Quote (string var) -> string

Quote a string with 's

More precisely it protects single quotes inside the string but does not prepend or append single quotes.

Parameters:
var unquoted string
Return value:
quoted string
Example
 quote("a'b") -> "a'\''b"
global UnQuote (string var) -> string

Unquote a string with 's (quoted with quote)

Parameters:
var quoted string
Return value:
unquoted string
See
quote
global OptFormat (string f, string s) -> string

Optional formatted text

Parameters:
f
s
Return value:
sformat (f, s) if s is neither empty or nil, else ""
global OptParens (string s) -> string

Optional parenthesized text

Parameters:
s
Return value:
" (Foo)" if Foo is neither empty or nil, else ""
global NonEmpty (list<string> l) -> list<string>

Parameters:
l a list of strings
Return value:
only non-"" items
global NewlineItems (string s) -> list<string>

Parameters:
s \n-terminated items
Return value:
the items as a list, with empty lines removed
global YesNo (boolean value) -> string

Parameters:
value boolean
Return value:
value as "Yes" or "No"
global FormatSizeWithPrecision (integer bytes, integer precision, boolean omit_zeroes) -> string

Return a pretty description of a byte count

Return a pretty description of a byte count with required precision and using B, kB, MB, GB or TB as unit as appropriate.

Uses the current locale defined decimal separator (i.e. the result is language dependant).

Parameters:
bytes size (e.g. free diskspace, memory size) in Bytes
precision number of fraction digits in output, if negative (less than 0) the precision is set automatically depending on the suffix
omit_zeroes if true then do not add zeroes (useful for memory size - 128 MB RAM looks better than 128.00 MB RAM)
Return value:
formatted string
Example
 FormatSizeWithPrecision(128, 2, true) -> "128 B"
 FormatSizeWithPrecision(4096, 2, true) -> "4 kB"
 FormatSizeWithPrecision(4096, 2, false) -> "4.00 kB"
 FormatSizeWithPrecision(1024*1024, 2, true) -> "1 MB"
global FormatSize (integer bytes) -> string

Return a pretty description of a byte count

Return a pretty description of a byte count, with two fraction digits and using B, kB, MB, GB or TB as unit as appropriate.

Uses the current locale defined decimal separator (i.e. the result is language dependant).

Parameters:
bytes size (e.g. free diskspace) in Bytes
Return value:
formatted string
Example
 FormatSize(23456767890) -> "223.70 MB"
global FormatRate (integer bytes_per_second) -> string

Return a pretty description of a download rate

Return a pretty description of a download rate, with two fraction digits and using B/s, kB/s, MB/s, GB/s or TB/s as unit as appropriate.

Parameters:
bytes_per_second download rate (in B/s)
Return value:
formatted string
Example
 FormatRate(6780) -> ""
 FormatRate(0) -> ""
 FormatRate(895321) -> ""
global FormatRateMessage (string text, integer avg_bps, integer curr_bps) -> string

Add a download rate status to a message.

Add the current and the average download rate to the message.

Parameters:
text the message with %1 placeholder for the download rate string
avg_bps average download rate (in B/s)
curr_bps current download rate (in B/s)
Return value:
formatted message
local FormatTwoDigits (integer x) -> string

Format an integer number as (at least) two digits; use leading zeroes if necessary.

Parameters:
x input
Return value:
number as two-digit string
global FormatTime (integer seconds) -> string

Format an integer seconds value with min:sec or hours:min:sec

Parameters:
seconds time (in seconds)
Return value:
formatted string (empty for negative values)
global CutBlanks (string input) -> string

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"
global CutZeros (string input) -> string

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
global Repeat (string text, integer number) -> string

Repeat a string

Repeat a string number of times.

Parameters:
text
number
Return value:
repeated string
global SuperPad (string text, integer length, string padding, symbol alignment) -> string

Add the padding character around the text to make it long enough

Add the padding character around 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
padding padding character
alignment alignment to use, either `left or `right
Return value:
padded text
global Pad (string text, integer length) -> string

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
global PadZeros (string text, integer length) -> string

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
global ParseOptions (string options, map parameters) -> list<string>

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
global CutRegexMatch (string input, string regex, boolean glob) -> string

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
global EscapeTags (string text) -> string

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
global FirstChunk (string s, string separators) -> string

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 ""
global CUpper () -> string

The 26 uppercase ASCII letters

global CLower () -> string

The 26 lowercase ASCII letters

global CAlpha () -> string

The 52 upper and lowercase ASCII letters

global CDigit () -> string

Digits: 0123456789

global CXdigit () -> string

Hexadecimal digits: 0123456789ABCDEFabcdef

global CAlnum () -> string

The 62 upper and lowercase ASCII letters and digits

global CPunct () -> string

The ASCII printable non-blank non-alphanumeric characters

global CGraph () -> string

Printable ASCII charcters except whitespace, 33-126

global CSpace () -> string

ASCII whitespace: SPACE CR LF HT VT FF

global CPrint () -> string

Printable ASCII characters including whitespace

global ValidCharsFilename () -> string

Characters valid in a filename (not pathname). Naturally "/" is disallowed. Otherwise, the graphical ASCII characters are allowed.

Return value:
for ValidChars
global TextTable (list<string> header, list <list <string> > items, map <string, any> options) -> string

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)
global UnderlinedHeader (string header_line, integer left_padding) -> string

Function returns underlined text header without using HTML tags. (Useful for commandline)

Parameters:
header_line
left_padding
Return value:
underlined header line
global GetMetaDataLines (string input) -> list<string>

Get metadata lines from input string

Parameters:
input Input string - complete comment of a sysconfig variable
Return value:
Metadata lines in list
global GetCommentLines (string input) -> string

Get comment without metadata

Parameters:
input Input string - complete comment of a sysconfig variable
Return value:
Comment used as variable description
global ParseSysconfigComment (string comment) -> map<string, string>

Parse metadata from a sysconfig comment

Parameters:
comment comment of a sysconfig variable (single line or multiline string)
Return value:
parsed metadata
global Replace (string s, string source, string target) -> string

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
global WrapAt (string text, integer width, string split_string) -> string

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,"/-");
global Random (integer len) -> string

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
global FormatFilename (string file_path, integer len) -> string

Format file name - truncate the middle part of the directory to fit to the reqested lenght. Path elements in the middle of the string are replaced by ellipsis (...). The result migth be longer that requested size if size of the last element (with ellipsis) is longer than the requested size. If the requested size is greater than size of the input then the string is not modified. The last part (file name) is never removed.

Parameters:
file_path file name
len requested maximum lenght of the output
Return value:
Truncated file name
Example
 FormatFilename("/really/very/long/file/name", 15) -> "/.../file/name"
 FormatFilename("/really/very/long/file/name", 5) -> ".../name"
 FormatFilename("/really/very/long/file/name", 100) -> "/really/very/long/file/name"
global RemoveShortcut (string label) -> string

Remove a shortcut from a label, so that it can be inserted into help to avoid risk of different translation of the label

Parameters:
label string a label possibly including a shortcut
Return value:
the label without the shortcut mark
global StartsWith (string str, string test) -> boolean

Checks whether string str starts with test.

Parameters:
str
test
global ReplaceWith (string str, string chars, string glue) -> string

Replaces all characters in a given string with some other string or character

Parameters:
str
chars
glue
Example

   // Replace whitespace characters with dashes
   ReplaceWith ("a\nb\tc d", "\n\t ", "-") -> "a-b-c-d"