// genereate a list of blocks describing the characters private List <CharacterDescriptor>[] generateCharacterDescriptorBlockList() { char currentCharacter, previousCharacter = '\0'; List <List <CharacterDescriptor> > characterBlockList = new List <List <CharacterDescriptor> >(); // initialize first block List <CharacterDescriptor> characterBlock = null; CodePageInfo cpi = new CodePageInfo(OutConfig.CodePage); // get the difference between two characters required to create a new group int differenceBetweenCharsForNewGroup = OutConfig.generateLookupBlocks ? OutConfig.lookupBlocksNewAfterCharCount : int.MaxValue; // iterate over characters, saving previous character each time for (int charIndex = 0; charIndex < Characters.Length; ++charIndex) { // get character currentCharacter = Characters[charIndex].Character; // check if this character is too far from the previous character and it isn't the first char if (cpi.GetCharacterDifferance(previousCharacter, currentCharacter) < differenceBetweenCharsForNewGroup && previousCharacter != '\0') { // it may not be far enough to generate a new group but it still may be non-sequential // in this case we need to generate place holders int previousCharacterOffset = cpi.GetOffsetFromCharacter(previousCharacter); int currentCharacterOffset = cpi.GetOffsetFromCharacter(currentCharacter); for (int sequentialCharIndex = previousCharacterOffset + 1; sequentialCharIndex < currentCharacterOffset; ++sequentialCharIndex) { // add the character placeholder to the current char block characterBlock.Add(new CharacterDescriptor(this)); } // fall through and add to current block } else { // done with current block, add to list (null is for first character which hasn't // created a group yet) if (characterBlock != null) { characterBlockList.Add(characterBlock); } // create new block characterBlock = new List <CharacterDescriptor>(); } // add to current block characterBlock.Add(Characters[charIndex]); // save previous char previousCharacter = currentCharacter; } // done; add current block to list characterBlockList.Add(characterBlock); return(characterBlockList.ToArray()); }
// get the characters we need to generate private static char[] getCharactersToGenerate(string inputText, int codePage, bool generateSpace) { CodePageInfo cpi = new CodePageInfo(codePage); // Expand and remove all ranges from the input text (look for << x - y >> // expand the ranges into the input text inputText = expandAndRemoveCharacterRanges(inputText, codePage); List <char> characterList = new List <char>(); List <char> CodePageCharacterList = new List <char>(cpi.GetAllValidCharacter()); // iterate over the characters in the textbox characterList = inputText.Aggregate <char, List <char> >(new List <char>(), (list, c) => { if (c == ' ' && !generateSpace) { } // skip - space is not encoded rather generated dynamically by the driver else if (c == '\n' || c == '\r' || c == '\t') { } // dont generate newlines or tab else { list.Add(c); } return(list); }); // remove dublicats and sort // remove all charaters not includet in codepage and return return(CodePageCharacterList .Intersect(characterList) .Distinct() .OrderBy(p => cpi.GetOffsetFromCharacter(p)) .ToArray()); }
// get the display string for a character private static string getCharacterDisplayString(CodePageInfo codePage, char character) { // return string return(codePage.GetOffsetFromCharacter(character).ToString()); }