//TH-Header //***************************************************************************************** // Copyright (c) 2017 The Kurant project // All rights reserved. // // $FileName : .\Hammer\Pkg\cNormalizeCase.pkg // $ProjectName : TheHammer3 // $Authors : Wil van Antwerpen // $Created : 07.06.2017 13:30 // // Contents: // Contains the logic to be able to store the keywords and scopewords of a language so // that this can be used to adjust the casing to the preferred casing as is defined in // the language configuration. // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd Struct tWordCaseAdjust Integer iLanguage String[] KeyWords String[] ScopeWords End_Struct Class cNormalizeCase is a cObject Procedure Construct_Object Forward Send Construct_Object Property tWordCaseAdjust[] pTextAdjust End_Procedure Function WordsToArray String sWords Returns String[] Integer iPos String sNewWord String[] Words While (sWords<>"") Move (Pos(" ",sWords)) To iPos If (iPos>0) Begin Move (Left(sWords,iPos-1)) To sNewWord Move sNewWord To Words[SizeOfArray(Words)] Move (Replace(sNewWord+" ",sWords,"")) To sWords End Else Begin Move sWords To Words[SizeOfArray(Words)] Move "" To sWords End Loop Function_Return Words End_Function Procedure AddKeywords Integer iLanguage String sKeyWords Boolean bInitialized Integer iItem String[] Words tWordCaseAdjust[] TextAdjusts Move False To bInitialized Get pTextAdjust To TextAdjusts Get WordsToArray sKeyWords To Words Get InitializedLanguage iLanguage To bInitialized If (bInitialized=False) Begin Move (SizeOfArray(TextAdjusts)) To iItem Move iLanguage To TextAdjusts[iItem].iLanguage Move Words To TextAdjusts[iItem].KeyWords End Else Begin Get LanguageItem iLanguage To iItem Move (AppendArray(Words,TextAdjusts[iItem].KeyWords)) To TextAdjusts[iItem].KeyWords End Move (SortArray(TextAdjusts[iItem].KeyWords, Desktop, (RefFunc(DFSTRICMP)))) To TextAdjusts[iItem].KeyWords Set pTextAdjust To TextAdjusts End_Procedure Procedure AddScopewords Integer iLanguage String sScopeWords Boolean bInitialized Integer iItem String[] Words tWordCaseAdjust[] TextAdjusts Move False To bInitialized Get pTextAdjust To TextAdjusts Get WordsToArray sScopeWords To Words Get InitializedLanguage iLanguage To bInitialized If (bInitialized=False) Begin Move (SizeOfArray(TextAdjusts)) To iItem Move iLanguage To TextAdjusts[iItem].iLanguage Move Words To TextAdjusts[iItem].ScopeWords End Else Begin Get LanguageItem iLanguage To iItem Move (AppendArray(Words,TextAdjusts[iItem].ScopeWords)) To TextAdjusts[iItem].ScopeWords End Move (SortArray(TextAdjusts[iItem].ScopeWords, Desktop, (RefFunc(DFSTRICMP)))) To TextAdjusts[iItem].ScopeWords Set pTextAdjust To TextAdjusts End_Procedure Function FindKeyWord Integer iLanguage String sKeyWord Returns String Integer iItem Integer iSearchIndex String sWord tWordCaseAdjust[] TextAdjusts Get LanguageItem iLanguage To iItem If (iItem>-1) Begin Get pTextAdjust To TextAdjusts Move (BinarySearchArray(sKeyWord, TextAdjusts[iItem].KeyWords, Desktop, (RefFunc(DFSTRICMP)))) To iSearchIndex If (iSearchIndex>-1) Begin Move TextAdjusts[iItem].KeyWords[iSearchIndex] To sWord End Else ; Move sKeyWord To sWord End Else ; Move sKeyWord To sWord // not found, return word unchanged Function_Return sWord End_Function Function FindScopeWord Integer iLanguage String sScopeWord Returns String Integer iItem Integer iSearchIndex String sWord tWordCaseAdjust[] TextAdjusts Get LanguageItem iLanguage To iItem If (iItem>-1) Begin Get pTextAdjust To TextAdjusts Move (BinarySearchArray(sScopeWord, TextAdjusts[iItem].ScopeWords, Desktop, (RefFunc(DFSTRICMP)))) To iSearchIndex If (iSearchIndex>-1) Begin Move TextAdjusts[iItem].ScopeWords[iSearchIndex] To sWord End Else ; Move sScopeWord To sWord End Else ; Move sScopeWord To sWord // not found, return word unchanged Function_Return sWord End_Function Function LanguageItem Integer iLanguage Returns Integer Integer iItem iCount iFound tWordCaseAdjust[] TextAdjusts Move -1 To iFound Get pTextAdjust To TextAdjusts Move (SizeOfArray(TextAdjusts)) To iCount If (iCount>0) Begin For iItem From 0 To (iCount-1) If (TextAdjusts[iItem].iLanguage=iLanguage) Begin Move iItem To iFound Move iCount To iItem End Loop End Function_Return iFound End_Function Function InitializedLanguage Integer iLanguage Returns Boolean Boolean bInitialized Integer iItem iCount tWordCaseAdjust[] TextAdjusts Move False To bInitialized Get pTextAdjust To TextAdjusts Move (SizeOfArray(TextAdjusts)) To iCount If (iCount>0) Begin For iItem From 0 To (iCount-1) If (TextAdjusts[iItem].iLanguage=iLanguage) Begin Move True To bInitialized Move iCount To iItem End Loop End Function_Return bInitialized End_Function End_Class Object oNormalizeCase is a cNormalizeCase End_Object