commit 815472cc1964c5c2ab6b8cc9a590b2e1a2dd7034 Author: Daniel Swanson Date: Fri Jul 2 10:11:30 2021 -0500 shouldn't change case of tags diff --git a/apertium/interchunk.cc b/apertium/interchunk.cc index e52c500..77c0109 100644 --- a/apertium/interchunk.cc +++ b/apertium/interchunk.cc @@ -84,8 +84,8 @@ Interchunk::evalCachedString(xmlNode* element) case ti_get_case_from: if (checkIndex(element, ti.getPos(), lword)) { - return StringUtils::copycase(word[ti.getPos()]->chunkPart(attr_items[ti.getContent()]), - evalString(ti.getPointer())); + return copycase(word[ti.getPos()]->chunkPart(attr_items[ti.getContent()]), + evalString(ti.getPointer())); } break; diff --git a/apertium/postchunk.cc b/apertium/postchunk.cc index b1b2c50..0707e14 100644 --- a/apertium/postchunk.cc +++ b/apertium/postchunk.cc @@ -93,8 +93,8 @@ Postchunk::evalCachedString(xmlNode* element) case ti_get_case_from: if (checkIndex(element, ti.getPos(), lword)) { - return StringUtils::copycase(word[ti.getPos()]->chunkPart(attr_items[ti.getContent()]), - evalString(ti.getPointer())); + return copycase(word[ti.getPos()]->chunkPart(attr_items[ti.getContent()]), + evalString(ti.getPointer())); } break; diff --git a/apertium/transfer.cc b/apertium/transfer.cc index 83d876c..673d259 100644 --- a/apertium/transfer.cc +++ b/apertium/transfer.cc @@ -199,8 +199,8 @@ Transfer::evalCachedString(xmlNode *element) case ti_get_case_from: if(checkIndex(element, ti.getPos(), lword)) { - return StringUtils::copycase(word[ti.getPos()]->source(attr_items[ti.getContent()]), - evalString(ti.getPointer())); + return copycase(word[ti.getPos()]->source(attr_items[ti.getContent()]), + evalString(ti.getPointer())); } break; diff --git a/apertium/transfer_base.cc b/apertium/transfer_base.cc index 2974716..e16ec92 100644 --- a/apertium/transfer_base.cc +++ b/apertium/transfer_base.cc @@ -180,6 +180,28 @@ TransferBase::combineWblanks(const UString& first, const UString& second) return ret; } +UString +TransferBase::copycase(const UString& src, const UString& dest) +{ + auto loc = dest.find('<'); + auto loc2 = dest.rfind('>'); + if (loc == UString::npos || loc2 == UString::npos) { + return StringUtils::copycase(src, dest); + } else { + UString cs = StringUtils::getcase(src); + UString ret = StringUtils::copycase(cs, dest.substr(0, loc)); + ret += dest.substr(loc, loc2 - loc + 1); + if (loc2 + 1 < dest.size()) { + if (u_isupper(cs[1])) { + ret += StringUtils::toupper(dest.substr(loc2+1)); + } else { + ret += StringUtils::tolower(dest.substr(loc2+1)); + } + } + return ret; + } +} + UString TransferBase::evalString(xmlNode* element) { diff --git a/apertium/transfer_base.h b/apertium/transfer_base.h index e283329..d926460 100644 --- a/apertium/transfer_base.h +++ b/apertium/transfer_base.h @@ -60,12 +60,13 @@ protected: bool null_flush; bool internal_null_flush; bool trace; - + void collectMacros(xmlNode *localroot); void collectRules(xmlNode *localroot); bool gettingLemmaFromWord(const UString& attr); UString combineWblanks(const UString& first, const UString& second); + UString copycase(const UString& src, const UString& dest); UString evalString(xmlNode* element); virtual UString evalCachedString(xmlNode* element) = 0; @@ -94,7 +95,7 @@ protected: bool processAnd(xmlNode *localroot); bool processOr(xmlNode *localroot); bool processNot(xmlNode *localroot); - + bool beginsWith(const UString& haystack, const UString& needle); bool endsWith(const UString& haystack, const UString& needle);