diff --git a/tutorial-02/spec/KBFuncs.nlp b/tutorial-02/spec/KBFuncs.nlp index 75e2d18..8bf63ba 100644 --- a/tutorial-02/spec/KBFuncs.nlp +++ b/tutorial-02/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/tutorial-03/spec/KBFuncs.nlp b/tutorial-03/spec/KBFuncs.nlp index 75e2d18..8bf63ba 100644 --- a/tutorial-03/spec/KBFuncs.nlp +++ b/tutorial-03/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/tutorial-06/spec/KBFuncs.nlp b/tutorial-06/spec/KBFuncs.nlp index 75e2d18..8bf63ba 100644 --- a/tutorial-06/spec/KBFuncs.nlp +++ b/tutorial-06/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/tutorial-08/spec/KBFuncs.nlp b/tutorial-08/spec/KBFuncs.nlp index 75e2d18..8bf63ba 100644 --- a/tutorial-08/spec/KBFuncs.nlp +++ b/tutorial-08/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/tutorial-11/spec/KBFuncs.nlp b/tutorial-11/spec/KBFuncs.nlp index 28a9656..39192d4 100644 --- a/tutorial-11/spec/KBFuncs.nlp +++ b/tutorial-11/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/tutorial-13/tutorial-13-b/spec/KBFuncs.nlp b/tutorial-13/tutorial-13-b/spec/KBFuncs.nlp index fd639c3..e273d50 100644 --- a/tutorial-13/tutorial-13-b/spec/KBFuncs.nlp +++ b/tutorial-13/tutorial-13-b/spec/KBFuncs.nlp @@ -150,13 +150,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/tutorial-15/spec/KBFuncs.nlp b/tutorial-15/spec/KBFuncs.nlp index c4762f5..b38a36f 100644 --- a/tutorial-15/spec/KBFuncs.nlp +++ b/tutorial-15/spec/KBFuncs.nlp @@ -173,13 +173,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")); }