Skip to content

Commit

Permalink
add sep to _S and _s.
Browse files Browse the repository at this point in the history
  • Loading branch information
yilabs committed May 14, 2023
1 parent 987b75d commit 117e8cc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions source/jdiutil/jdiutil.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ string _collectVar(ref string[] ids, string _id, bool showvar) {
return varfmt;
}

string _collectVars(ref string[] ids, string _id, bool showvar) {
string _collectVars(ref string[] ids, string _id, bool showvar, string sep) {
auto vars = _id.split(";").map!(id => _collectVar(ids, id, showvar));
return join(vars, " ");
return join(vars, sep);
}


// from https://github.com/ShigekiKarita/stri/blob/master/source/stri.d
auto parse(string s, bool showvar) {
auto parse(string s, bool showvar, string sep) {

string fmt = s;
string[] ids;
Expand All @@ -54,23 +54,23 @@ auto parse(string s, bool showvar) {

auto quote = subs[0..$+1-ends.length]; // "${def}"
auto _id = subs[1..$-ends.length]; // "def"
string varfmt = _collectVars(ids, _id, showvar);
string varfmt = _collectVars(ids, _id, showvar, sep);
fmt = fmt.replace(quote, varfmt);

subs = ends.find("{"); // "${i}..."
}
return tuple!("ids", "fmt")(ids, fmt);
}

string _interp(string sfmt, bool showvar)() {
enum _ret = parse(sfmt, showvar);
string _interp(string sfmt, bool showvar, string sep)() {
enum _ret = parse(sfmt, showvar, sep);
return format!`format!"%s"(%-(%s, %))`(_ret.fmt, _ret.ids);
}


// space separator
string _S(string sfmt)() {return _interp!(sfmt, true );}
string _s(string sfmt)() {return _interp!(sfmt, false);}
string _S(string sfmt, string sep=" ")() {return _interp!(sfmt, true , sep);}
string _s(string sfmt, string sep=" ")() {return _interp!(sfmt, false, sep);}

// TODO: comma separator

Expand Down

0 comments on commit 117e8cc

Please sign in to comment.