diff --git a/strings.scad b/strings.scad index 60744a17..81a911ed 100644 --- a/strings.scad +++ b/strings.scad @@ -42,7 +42,7 @@ function substr(str, pos=0, len=undef) = : _substr(str,pos,len); function _substr(str,pos,len) = - assert(pos>=0,"pos value for substr() must be nonnegative") + assert(pos>=0,"\npos value for substr() must be nonnegative.") len <= 0 || pos>=len(str) ? "" : chr([for(i=[pos:pos+len-1]) ord(str[i])]); @@ -78,7 +78,7 @@ function suffix(str,len) = // By default `str_find()` returns the index of the first match in `str`. If `last` is true then it returns the index of the last match. // If the pattern is the empty string the first match is at zero and the last match is the last character of the `str`. // If `start` is set then the search begins at index start, working either forward and backward from that position. If you set `start` -// and `last` is true then the search will find the pattern if it begins at index `start`. If no match exists, returns `undef`. +// and `last` is true then the search finds the pattern if it begins at index `start`. If no match exists, returns `undef`. // If you set `all` to true then `str_find()` returns all of the matches in a list, or an empty list if there are no matches. // Arguments: // str = String to search. @@ -103,8 +103,8 @@ function suffix(str,len) = // m=str_find("abc123def123abc","1234",all=true); // Returns [] // n=str_find("abc","",all=true); // Returns [0,1,2] function str_find(str,pattern,start=undef,last=false,all=false) = - assert(_is_liststr(str), "str must be a string or list") - assert(_is_liststr(pattern), "pattern must be a string or list") + assert(_is_liststr(str), "\nstr must be a string or list.") + assert(_is_liststr(pattern), "\npattern must be a string or list.") all? _str_find_all(str,pattern) : let( start = first_defined([start,last?len(str)-len(pattern):0]) ) pattern==""? start : @@ -153,8 +153,8 @@ function _str_find_all(str,pattern) = // cuts run time in half when the string is long. Two other string // comparison methods were slower. function substr_match(str,start,pattern) = - assert(_is_liststr(str), "str must be a string or list") - assert(_is_liststr(pattern), "pattern must be a string or list") + assert(_is_liststr(str), "\nstr must be a string or list.") + assert(_is_liststr(pattern), "\npattern must be a string or list.") len(str)-start =0 ? chr(repeat(ord(space_figure),sep)) : is_string(sep) ? sep - : assert(false,"Invalid separator: must be a string or positive integer giving number of spaces"), + : assert(false,"\nInvalid separator: must be a string or positive integer giving number of spaces."), strarr= [for(row=M) [for(entry=row) @@ -762,13 +792,13 @@ function _format_matrix(M, sig=4, sep=1, eps=1e-9) = // Given a format string and a list of values, inserts the values into the placeholders in the format string and returns it. // Formatting placeholders have the following syntax: // - A leading `{` character to show the start of the placeholder. -// - An integer index into the `vals` list to specify which value should be formatted at that place. If not given, the first placeholder will use index `0`, the second will use index `1`, etc. +// - An integer index into the `vals` list to specify which value should be formatted at that place. If not given, the first placeholder uses index `0`, the second uses index `1`, etc. // - An optional `:` separator to indicate that what follows if a formatting specifier. If not given, no formatting info follows. // - An optional `-` character to indicate that the value should be left justified if the value needs field width padding. If not given, right justification is used. -// - An optional `0` character to indicate that the field should be padded with `0`s. If not given, spaces will be used for padding. -// - An optional integer field width, which the value should be padded to. If not given, no padding will be performed. +// - An optional `0` character to indicate that the field should be padded with `0`s. If not given, spaces are used for padding. +// - An optional integer field width, which the value should be padded to. If not given, no padding is performed. // - An optional `.` followed by an integer precision length, for specifying how many digits to display in numeric formats. If not give, 6 digits is assumed. -// - An optional letter to indicate the formatting style to use. If not given, `s` is assumed, which will do it's generic best to format any data type. +// - An optional letter to indicate the formatting style to use. If not given, `s` is assumed, which does its generic best to format any data type. // - A trailing `}` character to show the end of the placeholder. // . // Formatting styles, and their effects are as follows: @@ -798,7 +828,7 @@ function format(fmt, vals) = for(i = idx(parts)) let( found_brace = i==0 || [for (c=parts[i]) if(c=="}") c] != [], - err = assert(found_brace, "Unbalanced { in format string."), + err = assert(found_brace, "\nUnbalanced { in format string."), p = i==0? [undef,parts[i]] : str_split(parts[i],"}"), fmta = p[0], raw = p[1] @@ -831,7 +861,7 @@ function format(fmt, vals) = typ=="F"? upcase(format_fixed(val,default(prec,6))) : typ=="g"? downcase(format_float(val,default(prec,6))) : typ=="G"? upcase(format_float(val,default(prec,6))) : - assert(false,str("Unknown format type: ",typ)), + assert(false,str("\nUnknown format type \"",typ,"\".")), padlen = max(0,wid-len(unpad)), padfill = chr([for (i=[0:1:padlen-1]) zero? 48 : 32]), out = left? str(unpad, padfill) : str(padfill, unpad)