Difference between revisions of "S2 functions"
From Dreamwidth Notes
m (corrected headers in template) |
(→Other: builtin functions from int and string classes) |
||
Line 19: | Line 19: | ||
= Other = | = Other = | ||
+ | |||
+ | == int = | ||
+ | |||
+ | === zeropad(int digits) = | ||
+ | |||
+ | * '''Name:''' zeropad(int digits) : string | ||
+ | * '''Description:''' Return the integer as a string formatted at least $digits characters long, left-padded with zeroes. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === compare(int n) = | ||
+ | |||
+ | * '''Name:''' compare(int n) : int | ||
+ | * '''Description:''' Compare one integer with another. Returns a negative number if n is less than the subject, positive if greater or zero if the two are numerically equal. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | == string = | ||
+ | |||
+ | === index(string sub) = | ||
+ | |||
+ | * '''Name:''' index(string sub) : int | ||
+ | * '''Description:''' Returns the index of the first instance of $sub in string. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === index(string sub, int position) = | ||
+ | |||
+ | * '''Name:''' index(string sub, int position) : int | ||
+ | * '''Description:''' Returns the index of the first instance of $sub in string, starting from $position. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === substr(int start, int length) = | ||
+ | |||
+ | * '''Name:''' substr(int start, int length) : string | ||
+ | * '''Description:''' Returns up to $length characters from string, skipping $start characters from the beginning. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === ends_with (string sub) = | ||
+ | |||
+ | * '''Name:''' ends_with (string sub) : bool | ||
+ | * '''Description:''' Returns true if string ends in $sub. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === starts_with (string sub) = | ||
+ | |||
+ | * '''Name:''' starts_with (string sub) : bool | ||
+ | * '''Description:''' Returns true if string begins with $sub. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === contains (string sub) = | ||
+ | |||
+ | * '''Name:''' contains (string sub) : bool | ||
+ | * '''Description:''' Return true if string contains $sub. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === replace(string find, string replace) = | ||
+ | |||
+ | * '''Name:''' replace(string find, string replace) : string | ||
+ | * '''Description:''' Replace all instances of $find with $replace. Case sensitive. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === split (string sub) = | ||
+ | |||
+ | * '''Name:''' split (string sub) : string[] | ||
+ | * '''Description:''' Return an array of strings split by $sub. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === lower = | ||
+ | |||
+ | * '''Name:''' lower : string | ||
+ | * '''Description:''' Returns string in lower case. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === upper = | ||
+ | |||
+ | * '''Name:''' upper : string | ||
+ | * '''Description:''' Returns string in upper case. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === upperfirst = | ||
+ | |||
+ | * '''Name:''' upperfirst : string | ||
+ | * '''Description:''' Return string with the first character capitalized. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === length() = | ||
+ | |||
+ | * '''Name:''' length() : int | ||
+ | * '''Description:''' Return the number of characters in the string. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === repeat(int n) = | ||
+ | |||
+ | * '''Name:''' repeat(int n) : string | ||
+ | * '''Description:''' Returns the string repeated n times. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === compare(string s) = | ||
+ | |||
+ | * '''Name:''' compare(string s) : int | ||
+ | * '''Description:''' Compare one string with another. Returns a negative number if n is alphabetically before the subject, positive if greater or zero if the two are equal. Note that this function currently does a simple ASCII compare, not a proper unicode-aware sort. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === css_string() = | ||
+ | |||
+ | * '''Name:''' css_string() : string | ||
+ | * '''Description:''' Returns the string escaped and quoted as a CSS string literal, safe for insertion into a stylesheet. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === css_keyword() = | ||
+ | |||
+ | * '''Name:''' css_keyword() : string | ||
+ | * '''Description:''' If the string is syntactically valid as a CSS keyword (only letters and spaces) returns it, else returns an empty string. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === css_keyword_list() = | ||
+ | |||
+ | * '''Name:''' css_keyword_list() : string | ||
+ | * '''Description:''' Analyses the string as a space-separated list of CSS keywords and returns a string containing the items that are syntactically acceptable. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === css_keyword(string[] allowed) = | ||
+ | |||
+ | * '''Name:''' css_keyword(string[] allowed) : string | ||
+ | * '''Description:''' Same as [method[string.css_keyword()]] except also imposes a whitelist of valid keywords given in $allowed. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === css_keyword_list(string[] allowed) = | ||
+ | |||
+ | * '''Name:''' css_keyword_list(string[] allowed) : string | ||
+ | * '''Description:''' Same as [method[string.css_keyword_list()]] except also imposes a whitelist of valid keywords given in $allowed. | ||
+ | * '''Other info:''' | ||
+ | |||
+ | === css_length_value() = | ||
+ | |||
+ | * '''Name:''' css_length_value() : string | ||
+ | * '''Description:''' If the string contains a valid CSS length value, returns a canonical version. Else returns an empty string. | ||
+ | * '''Other:''' | ||
+ | |||
+ | === css_url_value = | ||
+ | |||
+ | * '''Name:''' css_url_value : string | ||
+ | * '''Description:''' If the string contains a valid HTTP or HTTPS URL it is returned. Otherwise, an empty string is returned. | ||
+ | * '''Other info:''' | ||
[[Category: Styles]] | [[Category: Styles]] |
Revision as of 18:18, 21 April 2009
S2 functions
Template to use:
= class name = == function name= * '''Name:''' the in-code name for the function * '''Description:''' the in-code description * '''Other info:''' further explanation, if needed
Note: Classes only need to be listed once; all of the functions in that class can be added under the one header.
Contents
- 1 User-overridable functions
- 2 Layout-overridable functions
- 3 Other
- 4 = int
- 5 == zeropad(int digits)
- 6 == compare(int n)
- 7 = string
- 8 == index(string sub)
- 9 == index(string sub, int position)
- 10 == substr(int start, int length)
- 11 == ends_with (string sub)
- 12 == starts_with (string sub)
- 13 == contains (string sub)
- 14 == replace(string find, string replace)
- 15 == split (string sub)
- 16 == lower
- 17 == upper
- 18 == upperfirst
- 19 == length()
- 20 == repeat(int n)
- 21 == compare(string s)
- 22 == css_string()
- 23 == css_keyword()
- 24 == css_keyword_list()
- 25 == css_keyword(string[] allowed)
- 26 == css_keyword_list(string[] allowed)
- 27 == css_length_value()
- 28 == css_url_value
User-overridable functions
Layout-overridable functions
Other
= int
== zeropad(int digits)
- Name: zeropad(int digits) : string
- Description: Return the integer as a string formatted at least $digits characters long, left-padded with zeroes.
- Other info:
== compare(int n)
- Name: compare(int n) : int
- Description: Compare one integer with another. Returns a negative number if n is less than the subject, positive if greater or zero if the two are numerically equal.
- Other info:
= string
== index(string sub)
- Name: index(string sub) : int
- Description: Returns the index of the first instance of $sub in string.
- Other info:
== index(string sub, int position)
- Name: index(string sub, int position) : int
- Description: Returns the index of the first instance of $sub in string, starting from $position.
- Other info:
== substr(int start, int length)
- Name: substr(int start, int length) : string
- Description: Returns up to $length characters from string, skipping $start characters from the beginning.
- Other info:
== ends_with (string sub)
- Name: ends_with (string sub) : bool
- Description: Returns true if string ends in $sub.
- Other info:
== starts_with (string sub)
- Name: starts_with (string sub) : bool
- Description: Returns true if string begins with $sub.
- Other info:
== contains (string sub)
- Name: contains (string sub) : bool
- Description: Return true if string contains $sub.
- Other info:
== replace(string find, string replace)
- Name: replace(string find, string replace) : string
- Description: Replace all instances of $find with $replace. Case sensitive.
- Other info:
== split (string sub)
- Name: split (string sub) : string[]
- Description: Return an array of strings split by $sub.
- Other info:
== lower
- Name: lower : string
- Description: Returns string in lower case.
- Other info:
== upper
- Name: upper : string
- Description: Returns string in upper case.
- Other info:
== upperfirst
- Name: upperfirst : string
- Description: Return string with the first character capitalized.
- Other info:
== length()
- Name: length() : int
- Description: Return the number of characters in the string.
- Other info:
== repeat(int n)
- Name: repeat(int n) : string
- Description: Returns the string repeated n times.
- Other info:
== compare(string s)
- Name: compare(string s) : int
- Description: Compare one string with another. Returns a negative number if n is alphabetically before the subject, positive if greater or zero if the two are equal. Note that this function currently does a simple ASCII compare, not a proper unicode-aware sort.
- Other info:
== css_string()
- Name: css_string() : string
- Description: Returns the string escaped and quoted as a CSS string literal, safe for insertion into a stylesheet.
- Other info:
== css_keyword()
- Name: css_keyword() : string
- Description: If the string is syntactically valid as a CSS keyword (only letters and spaces) returns it, else returns an empty string.
- Other info:
== css_keyword_list()
- Name: css_keyword_list() : string
- Description: Analyses the string as a space-separated list of CSS keywords and returns a string containing the items that are syntactically acceptable.
- Other info:
== css_keyword(string[] allowed)
- Name: css_keyword(string[] allowed) : string
- Description: Same as [method[string.css_keyword()]] except also imposes a whitelist of valid keywords given in $allowed.
- Other info:
== css_keyword_list(string[] allowed)
- Name: css_keyword_list(string[] allowed) : string
- Description: Same as [method[string.css_keyword_list()]] except also imposes a whitelist of valid keywords given in $allowed.
- Other info:
== css_length_value()
- Name: css_length_value() : string
- Description: If the string contains a valid CSS length value, returns a canonical version. Else returns an empty string.
- Other:
== css_url_value
- Name: css_url_value : string
- Description: If the string contains a valid HTTP or HTTPS URL it is returned. Otherwise, an empty string is returned.
- Other info: