Synopses, etc for strings.scad

This commit is contained in:
Revar Desmera 2023-04-28 19:23:15 -07:00
parent 0537baa84c
commit 939ab1000c

View file

@ -12,6 +12,9 @@
// Section: Extracting substrings // Section: Extracting substrings
// Function: substr() // Function: substr()
// Synopsis: Returns a substring from a string.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// newstr = substr(str, [pos], [len]); // newstr = substr(str, [pos], [len]);
// Description: // Description:
@ -38,6 +41,9 @@ function _substr(str,pos,len,substr="") =
// Function: suffix() // Function: suffix()
// Synopsis: Returns the last few characters of a string.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// newstr = suffix(str,len); // newstr = suffix(str,len);
// Description: // Description:
@ -55,6 +61,9 @@ function suffix(str,len) =
// Function: str_find() // Function: str_find()
// Synopsis: Finds a substring in a string.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// ind = str_find(str,pattern,[last=],[all=],[start=]); // ind = str_find(str,pattern,[last=],[all=],[start=]);
// Description: // Description:
@ -108,13 +117,16 @@ function _str_find_all(str,pattern) =
[for(i=[0:1:len(str)-len(pattern)]) if (substr_match(str,i,pattern)) i]; [for(i=[0:1:len(str)-len(pattern)]) if (substr_match(str,i,pattern)) i];
// Function: substr_match() // Function: substr_match()
// Synopsis: Returns true if the string `pattern` matches the string `str`.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage // Usage
// bool = substr_match(str,start,pattern); // bool = substr_match(str,start,pattern);
// Description: // Description:
// Returns true if the string `pattern` matches the string `str` starting // Returns true if the string `pattern` matches the string `str` starting
// at `str[start]`. If the string is too short for the pattern, or // at `str[start]`. If the string is too short for the pattern, or
// `start` is out of bounds---either negative or beyond the end of the // `start` is out of bounds either negative or beyond the end of the
// string---then substr_match returns false. // string then substr_match returns false.
// Arguments: // Arguments:
// str = String to search // str = String to search
// start = Starting index for search in str // start = Starting index for search in str
@ -142,6 +154,9 @@ function _substr_match_recurse(str,sindex,pattern,plen,pindex=0,) =
// Function: starts_with() // Function: starts_with()
// Synopsis: Returns true if the string starts with a given substring.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// bool = starts_with(str,pattern); // bool = starts_with(str,pattern);
// Description: // Description:
@ -158,6 +173,9 @@ function starts_with(str,pattern) = substr_match(str,0,pattern);
// Function: ends_with() // Function: ends_with()
// Synopsis: Returns true if the string ends with a given substring.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// bool = ends_with(str,pattern); // bool = ends_with(str,pattern);
// Description: // Description:
@ -175,6 +193,9 @@ function ends_with(str,pattern) = substr_match(str,len(str)-len(pattern),pattern
// Function: str_split() // Function: str_split()
// Synopsis: Splits a longer string wherever a given substring occurs.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// string_list = str_split(str, sep, [keep_nulls]); // string_list = str_split(str, sep, [keep_nulls]);
// Description: // Description:
@ -225,6 +246,9 @@ function _remove_empty_strs(list) =
// Function: str_join() // Function: str_join()
// Synopsis: Joints a list of strings into a single string.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// str = str_join(list, [sep]); // str = str_join(list, [sep]);
// Description: // Description:
@ -244,6 +268,9 @@ function str_join(list,sep="",_i=0, _result="") =
// Function: str_strip() // Function: str_strip()
// Synopsis: Strips given leading and trailing characters from a string.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// str = str_strip(s,c,[start],[end]); // str = str_strip(s,c,[start],[end]);
// Description: // Description:
@ -287,6 +314,9 @@ function str_strip(s,c,start,end) =
// Function: str_pad() // Function: str_pad()
// Synopsis: Pads a string to a given length.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// padded = str_pad(str, length, char, [left]); // padded = str_pad(str, length, char, [left]);
// Description: // Description:
@ -311,6 +341,9 @@ function str_pad(str,length,char=" ",left=false) =
// Function: str_replace_char() // Function: str_replace_char()
// Synopsis: Replace given chars in a string with another substring.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip()
// Usage: // Usage:
// newstr = str_replace_char(str, char, replace); // newstr = str_replace_char(str, char, replace);
// Description: // Description:
@ -324,6 +357,9 @@ function str_replace_char(str,char,replace) =
// Function: downcase() // Function: downcase()
// Synopsis: Lowercases all characters in a string.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip(), upcase(), downcase()
// Usage: // Usage:
// newstr = downcase(str); // newstr = downcase(str);
// Description: // Description:
@ -338,6 +374,9 @@ function downcase(str) =
// Function: upcase() // Function: upcase()
// Synopsis: Uppercases all characters in a string.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip(), upcase(), downcase()
// Usage: // Usage:
// newstr = upcase(str); // newstr = upcase(str);
// Description: // Description:
@ -354,6 +393,9 @@ function upcase(str) =
// Section: Random strings // Section: Random strings
// Function: rand_str() // Function: rand_str()
// Synopsis: Create a randomized string.
// Topics: Strings
// See Also: suffix(), str_find(), substr_match(), starts_with(), ends_with(), str_split(), str_join(), str_strip(), upcase(), downcase()
// Usage: // Usage:
// str = rand_str(n, [charset], [seed]); // str = rand_str(n, [charset], [seed]);
// Description: // Description:
@ -371,6 +413,9 @@ function rand_str(n, charset, seed) =
// Section: Parsing strings into numbers // Section: Parsing strings into numbers
// Function: parse_int() // Function: parse_int()
// Synopsis: Parse an integer from a string.
// Topics: Strings
// See Also: parse_int(), parse_float(), parse_frac(), parse_num()
// Usage: // Usage:
// num = parse_int(str, [base]) // num = parse_int(str, [base])
// Description: // Description:
@ -407,6 +452,9 @@ function _parse_int_recurse(str,base,i) =
// Function: parse_float() // Function: parse_float()
// Synopsis: Parse a float from a string.
// Topics: Strings
// See Also: parse_int(), parse_float(), parse_frac(), parse_num()
// Usage: // Usage:
// num = parse_float(str); // num = parse_float(str);
// Description: // Description:
@ -435,6 +483,9 @@ function parse_float(str) =
// Function: parse_frac() // Function: parse_frac()
// Synopsis: Parse a float from a fraction string.
// Topics: Strings
// See Also: parse_int(), parse_float(), parse_frac(), parse_num()
// Usage: // Usage:
// num = parse_frac(str,[mixed=],[improper=],[signed=]); // num = parse_frac(str,[mixed=],[improper=],[signed=]);
// Description: // Description:
@ -488,6 +539,9 @@ function parse_frac(str,mixed=true,improper=true,signed=true) =
// Function: parse_num() // Function: parse_num()
// Synopsis: Parse a float from a decimal or fraction string.
// Topics: Strings
// See Also: parse_int(), parse_float(), parse_frac(), parse_num()
// Usage: // Usage:
// num = parse_num(str); // num = parse_num(str);
// Description: // Description:
@ -508,6 +562,9 @@ function parse_num(str) =
// Section: Formatting numbers into strings // Section: Formatting numbers into strings
// Function: format_int() // Function: format_int()
// Synopsis: Formats an integer into a string, with possible leading zeros.
// Topics: Strings
// See Also: format_int(), format_fixed(), format_float(), format()
// Usage: // Usage:
// str = format_int(i, [mindigits]); // str = format_int(i, [mindigits]);
// Description: // Description:
@ -532,6 +589,9 @@ function format_int(i,mindigits=1) =
// Function: format_fixed() // Function: format_fixed()
// Synopsis: Formats a float into a string with a fixed number of decimal places.
// Topics: Strings
// See Also: format_int(), format_fixed(), format_float(), format()
// Usage: // Usage:
// s = format_fixed(f, [digits]); // s = format_fixed(f, [digits]);
// Description: // Description:
@ -556,6 +616,9 @@ function format_fixed(f,digits=6) =
// Function: format_float() // Function: format_float()
// Synopsis: Formats a float into a string with a given number of significant digits.
// Topics: Strings
// See Also: format_int(), format_fixed(), format_float(), format()
// Usage: // Usage:
// str = format_float(f,[sig]); // str = format_float(f,[sig]);
// Description: // Description:
@ -655,6 +718,9 @@ function _format_matrix(M, sig=4, sep=1, eps=1e-9) =
// Function: format() // Function: format()
// Synopsis: Formats multiple values into a string with a given format.
// Topics: Strings
// See Also: format_int(), format_fixed(), format_float(), format()
// Usage: // Usage:
// s = format(fmt, vals); // s = format(fmt, vals);
// Description: // Description:
@ -743,6 +809,9 @@ function format(fmt, vals) =
// Section: Checking character class // Section: Checking character class
// Function: is_lower() // Function: is_lower()
// Synopsis: Returns true if all characters in the string are lowercase.
// Topics: Strings
// See Also: is_lower(), is_upper(), is_digit(), is_hexdigit(), is_letter()
// Usage: // Usage:
// x = is_lower(s); // x = is_lower(s);
// Description: // Description:
@ -755,6 +824,9 @@ function is_lower(s) =
// Function: is_upper() // Function: is_upper()
// Synopsis: Returns true if all characters in the string are uppercase.
// Topics: Strings
// See Also: is_lower(), is_upper(), is_digit(), is_hexdigit(), is_letter()
// Usage: // Usage:
// x = is_upper(s); // x = is_upper(s);
// Description: // Description:
@ -767,6 +839,9 @@ function is_upper(s) =
// Function: is_digit() // Function: is_digit()
// Synopsis: Returns true if all characters in the string are decimal digits.
// Topics: Strings
// See Also: is_lower(), is_upper(), is_digit(), is_hexdigit(), is_letter()
// Usage: // Usage:
// x = is_digit(s); // x = is_digit(s);
// Description: // Description:
@ -779,6 +854,9 @@ function is_digit(s) =
// Function: is_hexdigit() // Function: is_hexdigit()
// Synopsis: Returns true if all characters in the string are hexidecimal digits.
// Topics: Strings
// See Also: is_lower(), is_upper(), is_digit(), is_hexdigit(), is_letter()
// Usage: // Usage:
// x = is_hexdigit(s); // x = is_hexdigit(s);
// Description: // Description:
@ -794,6 +872,9 @@ function is_hexdigit(s) =
// Function: is_letter() // Function: is_letter()
// Synopsis: Returns true if all characters in the string are letters.
// Topics: Strings
// See Also: is_lower(), is_upper(), is_digit(), is_hexdigit(), is_letter()
// Usage: // Usage:
// x = is_letter(s); // x = is_letter(s);
// Description: // Description: