S2 functions
From Dreamwidth Notes
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
- 3.1 int
- 3.2 string
- 3.2.1 index(string sub)
- 3.2.2 index(string sub, int position)
- 3.2.3 substr(int start, int length)
- 3.2.4 ends_with (string sub)
- 3.2.5 starts_with (string sub)
- 3.2.6 contains (string sub)
- 3.2.7 replace(string find, string replace)
- 3.2.8 split (string sub)
- 3.2.9 lower
- 3.2.10 upper
- 3.2.11 upperfirst
- 3.2.12 length()
- 3.2.13 repeat(int n)
- 3.2.14 compare(string s)
- 3.2.15 css_string()
- 3.2.16 css_keyword()
- 3.2.17 css_keyword_list()
- 3.2.18 css_keyword(string[] allowed)
- 3.2.19 css_keyword_list(string[] allowed)
- 3.2.20 css_length_value()
- 3.2.21 css_url_value
- 3.3 Color
- 3.3.1 Color(string s)
- 3.3.2 set_hsl (int h, int s, int v)
- 3.3.3 red(int r)
- 3.3.4 green(int g)
- 3.3.5 blue(int b)
- 3.3.6 red()
- 3.3.7 green()
- 3.3.8 blue()
- 3.3.9 hue(int h)
- 3.3.10 saturation(int s)
- 3.3.11 lightness(int v)
- 3.3.12 hue()
- 3.3.13 saturation()
- 3.3.14 lightness()
- 3.3.15 clone()
- 3.3.16 lighter()
- 3.3.17 lighter(int amt)
- 3.3.18 darker()
- 3.3.19 darker(int amt)
- 3.3.20 inverse()
- 3.3.21 average(Color other)
- 3.3.22 blend(Color other, int 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 info:
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:
Color
Color(string s)
- Name: Color(string s) : Color
- Description: Constructor for color class. Lets you make a Color object from a string of form #rrggbb.
- Other info:
set_hsl (int h, int s, int v)
- Name: set_hsl (int h, int s, int v)
- Description: Set the HSL value for a color class.
- Other info:
red(int r)
- Name: red(int r)
- 'Description: Set the red value. (0-255)
- Other info:
green(int g)
- Name: green(int g)
- Description: Set the green value. (0-255)
- Other info:
blue(int b)
- Name: blue(int b)
- Description: Set the blue value. (0-255)
- Other info:
red()
- Name: red() : int
- Description: Get the red value.
- Other info:
green()
- Name: green() : int
- Description: Get the green value.
- Other info:
blue()
- Name: blue() : int
- Description: Get the blue value.
- Other info:
hue(int h)
- Name: hue(int h)
- Description: Set the hue value. (0-255)
- Other info:
saturation(int s)
- Name: saturation(int s)
- Description: Set the saturation value. (0-255)
- Other info:
lightness(int v)
- Name: lightness(int v)
- Description: Set the lightness value. (0-255)
- Other info:
hue()
- Name: hue() : int
- Description: Get the hue value. (0-255)
- Other info:
saturation()
- Name: saturation() : int
- Description: Get the saturation value. (0-255)
- Other info:
lightness()
- Name: lightness() : int
- Description: Get the lightness value. (0-255)
- Other info:
clone()
- Name: clone() : Color
- Description: Returns identical color.
- Other info:
lighter()
- Name: lighter() : Color
- Description: Returns a new color with lightness increased by 30.
- Other info:
lighter(int amt)
- Name: lighter(int amt) : Color
- Description: Returns a new color with lightness increased by amount given.
- Other info:
darker()
- Name: darker() : Color
- Description: Returns a new color with lightness decreased by 30.
- Other info:
darker(int amt)
- Name: darker(int amt) : Color
- Description: Returns a new color with lightness decreased by amount given.
- Other info:
inverse()
- Name: inverse() : Color
- Description: Returns inverse of color.
- Other info:
average(Color other)
- Name: average(Color other) : Color
- Description: Returns color averaged with $other color.
- Other info:
blend(Color other, int value)
- Name: blend(Color other, int value) : Color
- Description: Returns color blended with $other color by percentage value (int between 0 and 100).
- Other info: