diff --git a/spec/KBFuncs.nlp b/spec/KBFuncs.nlp index 4c69f88..beb315e 100644 --- a/spec/KBFuncs.nlp +++ b/spec/KBFuncs.nlp @@ -117,13 +117,14 @@ CountName(L("con"),L("root")) { } StripEndDigits(L("name")) { + # "item12" -> "item". A name with no trailing digits comes back whole, + # an all-digit name gives 0. Positions only count up from 0, so a short + # name never reaches a negative strpiece position (which counts from the + # end since engine 4.2.15). if (strisdigit(L("name"))) return 0; - L("len") = strlength(L("name")) - 1; - L("i") = L("len") - 1; - L("str") = strpiece(L("name"),L("i"),L("len")); - while (strisdigit(L("str")) && L("i")) { + L("i") = strlength(L("name")) - 1; + while (L("i") > 0 && strisdigit(strpiece(L("name"),L("i"),L("i")))) { L("i")--; - L("str") = strpiece(L("name"),L("i"),L("len")); } return strpiece(L("name"),0,L("i")); } diff --git a/spec/funs.nlp b/spec/funs.nlp index 496eb30..c34dbfc 100644 --- a/spec/funs.nlp +++ b/spec/funs.nlp @@ -2037,8 +2037,11 @@ if (L("field")) else if (L("tot") > G("MAX")) # TRACK AND LIMIT. { L("del") = G("MAX") - G("LEN"); - L("xx") = strpiece(L("txt"),0,L("del")-1); - L("str") = L("str") + L("xx"); + if (L("del") > 0) # A 0 end of -1 would take the whole text. + { + L("xx") = strpiece(L("txt"),0,L("del")-1); + L("str") = L("str") + L("xx"); + } G("LEN") = G("MAX"); # TRACK AND LIMIT. return L("str"); } @@ -2093,8 +2096,8 @@ else if (L("ch") != "_" || L("nm") == "_") # Literal. Alpha, num, punct, etc. else if (L("tot") > G("MAX")) # HUGE TOKEN! { L("del") = G("MAX") - G("LEN"); - L("xx") = strpiece(L("nm"),0,L("del")-1); - L("str") = L("xx"); + if (L("del") > 0) # A 0 end of -1 would take the whole token. + L("str") = strpiece(L("nm"),0,L("del")-1); G("LEN") = G("MAX"); # TRACK AND LIMIT. return L("str"); }