/// <summary> /// Copies the entire sequence to a compatible one-dimensional array, /// starting at the specified index of the target array. /// </summary> /// <param name="array"> /// The one-dimensional array that is the destination of the elements /// copied from the current sequence. The array must have zero-based indexing. /// </param> /// <param name="arrayIndex">The zero-based index in the array at which copying begins.</param> public void CopyTo(ISequenceItem[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException(Properties.Resource.ParameterNameArray); } int index = arrayIndex; foreach (byte item in this) { array[index++] = _alphabet.LookupBySymbol((char)item); } }
// Does a direct symbol comparison to create the dictionary used in the mapping // This is a useful starting point for any map. The dictionary can then be customized // by adding or removing entries. internal static EncodingMap CreateBasicMap(IAlphabet alphabet, IEncoding encoding, EncodingMapDirection direction) { EncodingMap result = new EncodingMap(alphabet, encoding, direction); if (direction == EncodingMapDirection.AlphabetToEncoding) { result.map = GetMap( alphabet, item => encoding.LookupBySymbol(item.Symbol)); } else if (direction == EncodingMapDirection.EncodingToAlphabet) { result.map = GetMap( encoding, item => alphabet.LookupBySymbol(item.Symbol)); } return(result); }
/// <summary> /// Create a dictionary which has the mapping for ambiguous/unambiguous characters /// </summary> /// <summary> /// Find the list of characters that maps to the inputs symbol and applies the pattern rule. /// </summary> /// <param name="symbol">Character which has to be mapped.</param> private char[] MapSymbol(char symbol) { if (_alphabets.Contains(symbol)) { return(new char[] { symbol }); } switch (symbol) { case LeftAngle: case RightAngle: case Repeater: return(new char[] { symbol }); default: break; } return(_alphabetSet.GetBasicSymbols(_alphabetSet.LookupBySymbol(symbol)).Select(c => c.Symbol).ToArray()); }
// Does a direct symbol comparison to create the dictionary used in the mapping // This is a useful starting point for any map. The dictionary can then be customized // by adding or removing entries. internal static EncodingMap CreateBasicMap(IAlphabet alphabet, IEncoding encoding, EncodingMapDirection direction) { EncodingMap result = new EncodingMap(alphabet, encoding, direction); if (direction == EncodingMapDirection.AlphabetToEncoding) { foreach (ISequenceItem sourceItem in alphabet) { try { ISequenceItem resultItem = encoding.LookupBySymbol(sourceItem.Symbol); result.map[sourceItem] = resultItem; } catch (Exception) { // Ignore the exception and just continue filling the dictionary } } } else if (direction == EncodingMapDirection.EncodingToAlphabet) { foreach (ISequenceItem sourceItem in encoding) { try { ISequenceItem resultItem = alphabet.LookupBySymbol(sourceItem.Symbol); result.map[sourceItem] = resultItem; } catch (Exception) { // Ignore the exception and just continue filling the dictionary } } } return(result); }