From 712c756d1e42e388b9c426c026a81dcf0ba02249 Mon Sep 17 00:00:00 2001 From: David de Hilster Date: Sat, 24 Aug 2024 13:58:56 -0400 Subject: [PATCH] VISUAL-TEXT-108 Add MakeCountConPad Signed-off-by: David de Hilster --- spec/KBFuncs.nlp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/spec/KBFuncs.nlp b/spec/KBFuncs.nlp index 932ccbd..e2b5860 100644 --- a/spec/KBFuncs.nlp +++ b/spec/KBFuncs.nlp @@ -151,7 +151,12 @@ LastChild(L("parent")) { } MakeCountCon(L("con"),L("count name")) { - L("count name") = CountName(L("con"),L("count name")); + L("count name") = CountName(L("con"),L("count name"),0); + return makeconcept(L("con"),L("count name")); +} + +MakeCountConPad(L("con"),L("count name"),L("pad")) { + L("count name") = CountName(L("con"),L("count name"),L("pad")); return makeconcept(L("con"),L("count name")); } @@ -167,9 +172,14 @@ IncrementCount(L("con"),L("countname")) { return L("count"); } -CountName(L("con"),L("root")) { +CountName(L("con"),L("root"),L("pad")) { L("count") = IncrementCount(L("con"),L("root")); - return L("root") + str(L("count")); + if (L("pad")) { + L("pad") = RepeatStr(L("pad")-strlength(str(L("count"))),"0"); + } else { + L("pad") = SpacesStr(" "); + } + return L("root") + L("pad") + str(L("count")); } StripEndDigits(L("name")) { @@ -357,10 +367,14 @@ QuoteIfNeeded(L("str")) { # Because NLP++ doesn't allow for empty strings, # this function can only be called with "num" >= 1 SpacesStr(L("num")) { + return RepeatStr(L("num")," "); +} + +RepeatStr(L("num"),L("str")) { L("n") = 1; - L("spaces") = " "; + L("spaces") = L("str"); while (L("n") < L("num")) { - L("spaces") = L("spaces") + " "; + L("spaces") = L("spaces") + L("str"); L("n")++; } return L("spaces");