private int GetShapeableSymbolsWidth(TextShapeableSymbols textRun) { int result = 0; int text_length = textRun.Length; int[] advance_widths = new int[text_length]; GCHandle pin_handle; CharacterBuffer char_buf = textRun.CharacterBufferReference.CharacterBuffer; unsafe { IntPtr run_characters = char_buf.PinAndGetCharacterPointer(textRun.CharacterBufferReference.OffsetToFirstChar, out pin_handle); try { fixed(int *widths_ptr = advance_widths) { textRun.GetAdvanceWidthsUnshaped((char *)run_characters.ToPointer(), text_length, TextFormatterImp.ToIdeal, widths_ptr); } } finally { char_buf.UnpinCharacterPointer(pin_handle); } } for (int i = 0; i < text_length; i++) { result += advance_widths[i]; } return(result); }
public GrahpicsBuffer(int width, int height) { Width = width; Height = height; ZBuffer = new float?[width, height]; CharacterBuffer = new CharacterBuffer(width, height); ColorBuffer = new ColorBuffer(width, height); }
public void TestBuildString() { var buffer = new CharacterBuffer(); var s = "Some test string"; for (int i = 0; i < s.Length; i++) buffer.Append(s[i]); Assert.AreEqual(buffer.DisposeAndGetContents(), s); }
/// <summary> /// Construct character buffer from memory buffer /// </summary> internal CharacterBufferRange( CharacterBuffer charBuffer, int offsetToFirstChar, int characterLength ) : this( new CharacterBufferReference(charBuffer, offsetToFirstChar), characterLength ) { }
public void TestClear() { var buffer = new CharacterBuffer(); buffer.Append('a'); buffer.Append('b'); buffer.Clear(); buffer.Append('c'); Assert.AreEqual(buffer.DisposeAndGetContents(), "c"); }
public void TestRemoveLastCharacter() { var buffer = new CharacterBuffer(); int size = buffer.Capacity; for (int i = 0; i < size; i++) buffer.Append('a'); for (int i = 0; i < size; i++) buffer.Remove(buffer.Length - 1, 1); buffer.Dispose(); }
public override bool Fill(CharacterBuffer buffer, TextReader reader, int numChars) { Debug.Assert(buffer.Buffer.Length >= 1); if (numChars < 1 || numChars > buffer.Buffer.Length) { throw new ArgumentException("numChars must be >= 1 and <= the buffer size"); } buffer.offset = 0; int read = ReadFully(reader, buffer.Buffer, 0, numChars); buffer.length = read; buffer.lastTrailingHighSurrogate = (char)0; return(read == numChars); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public boolean fill(final CharacterBuffer buffer, final java.io.Reader reader, int numChars) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public override bool fill(CharacterBuffer buffer, Reader reader, int numChars) { Debug.Assert(buffer.buffer.Length >= 2); if (numChars < 2 || numChars > buffer.buffer.Length) { throw new System.ArgumentException("numChars must be >= 2 and <= the buffer size"); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final char[] charBuffer = buffer.buffer; char[] charBuffer = buffer.buffer; buffer.offset = 0; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int offset; int offset; // Install the previously saved ending high surrogate: if (buffer.lastTrailingHighSurrogate != 0) { charBuffer[0] = buffer.lastTrailingHighSurrogate; buffer.lastTrailingHighSurrogate = (char)0; offset = 1; } else { offset = 0; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int read = readFully(reader, charBuffer, offset, numChars - offset); int read = readFully(reader, charBuffer, offset, numChars - offset); buffer.length = offset + read; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final boolean result = buffer.length == numChars; bool result = buffer.length == numChars; if (buffer.length < numChars) { // We failed to fill the buffer. Even if the last char is a high // surrogate, there is nothing we can do return(result); } if (char.IsHighSurrogate(charBuffer[buffer.length - 1])) { buffer.lastTrailingHighSurrogate = charBuffer[--buffer.length]; } return(result); }
public Character Map(CharacterBuffer buff) { var character = new Character() { Name = buffer.Name, Bio = buffer.Bio, CampaignID = buffer.CampaignID, UserId = UserRepo.GetUserByUsername(buffer.Username).UserID, RaceID = buffer.RaceID, ClassID = buffer.ClassID, Experience = 0, Level = 1 }; return(character); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public boolean fill(CharacterBuffer buffer, java.io.Reader reader, int numChars) throws java.io.IOException public override bool fill(CharacterBuffer buffer, Reader reader, int numChars) { Debug.Assert(buffer.buffer.Length >= 1); if (numChars < 1 || numChars > buffer.buffer.Length) { throw new System.ArgumentException("numChars must be >= 1 and <= the buffer size"); } buffer.offset = 0; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int read = readFully(reader, buffer.buffer, 0, numChars); int read = readFully(reader, buffer.buffer, 0, numChars); buffer.length = read; buffer.lastTrailingHighSurrogate = (char)0; return(read == numChars); }
public override bool Fill(CharacterBuffer buffer, TextReader reader, int numChars) { if (Debugging.AssertsEnabled) { Debugging.Assert(buffer.Buffer.Length >= 2); } if (numChars < 2 || numChars > buffer.Buffer.Length) { // LUCENENET: Changed from InvalidArgumentException to ArgumentOutOfRangeException throw new ArgumentOutOfRangeException(nameof(numChars), "numChars must be >= 2 and <= the buffer size"); } char[] charBuffer = buffer.Buffer; buffer.offset = 0; int offset; // Install the previously saved ending high surrogate: if (buffer.lastTrailingHighSurrogate != 0) { charBuffer[0] = buffer.lastTrailingHighSurrogate; buffer.lastTrailingHighSurrogate = (char)0; offset = 1; } else { offset = 0; } int read = ReadFully(reader, charBuffer, offset, numChars - offset); buffer.length = offset + read; bool result = buffer.length == numChars; if (buffer.length < numChars) { // We failed to fill the buffer. Even if the last char is a high // surrogate, there is nothing we can do return(result); } if (char.IsHighSurrogate(charBuffer[buffer.length - 1])) { buffer.lastTrailingHighSurrogate = charBuffer[--buffer.length]; } return(result); }
public override bool Fill(CharacterBuffer buffer, TextReader reader, int numChars) { if (Debugging.AssertsEnabled) { Debugging.Assert(buffer.Buffer.Length >= 1); } if (numChars < 1 || numChars > buffer.Buffer.Length) { // LUCENENET: Changed from InvalidArgumentException to ArgumentOutOfRangeException throw new ArgumentOutOfRangeException(nameof(numChars), "numChars must be >= 1 and <= the buffer size"); } buffer.offset = 0; int read = ReadFully(reader, buffer.Buffer, 0, numChars); buffer.length = read; buffer.lastTrailingHighSurrogate = (char)0; return(read == numChars); }
public Comment(CharacterBuffer buffer) { //this.Image = ImageType.Comment; this.Start = buffer.IndexInOriginalBuffer; do { if (buffer.IsAtEnd) { break; } buffer.MoveNext(); } while (buffer.CurrentCharacter != '\n'); this.End = buffer.IndexInOriginalBuffer; this.Literal = buffer.Substring(this.Start - buffer.Offset, this.End - this.Start); this.contents = this.Literal.Remove(0, 1).Trim(); this.Description = string.Concat("Comment: ", this.contents); buffer.MoveNext(); }
private string _Collect(CharacterClass expect, char ch) { CharacterBuffer buf = new CharacterBuffer(ch); while (true) { int cur = _reader.Peek(); if (cur == -1) { break; } ch = (char)cur; CharacterClass cc = _settings.Classifier [ch]; if ((cc & expect) == 0) { break; } buf.Write((char)_reader.Read()); } return(buf.ToString()); }
public Character(CharacterBuffer buffer, bool repetitionsOnly) { //this.Image = ImageType.Character; Start = buffer.IndexInOriginalBuffer; if (buffer.IsAtEnd) { Utility.ParseError("Reached end of buffer in Character constructor!", buffer); IsValid = false; } else if (repetitionsOnly) { _character = buffer.CurrentCharacter.ToString(); ParseRepetitions(buffer); return; } _character = buffer.CurrentCharacter.ToString(); Literal = _character; Description = Literal; buffer.MoveNext(); ParseRepetitions(buffer); }
/// <summary> /// Construct character buffer reference from memory buffer /// </summary> internal CharacterBufferReference( CharacterBuffer charBuffer, int offsetToFirstChar ) { if (offsetToFirstChar < 0) { throw new ArgumentOutOfRangeException("offsetToFirstChar", SR.Get(SRID.ParameterCannotBeNegative)); } // maximum offset is one less than CharacterBuffer.Count, except that zero is always a valid offset // even in the case of an empty or null character buffer int maxOffset = (charBuffer == null) ? 0 : Math.Max(0, charBuffer.Count - 1); if (offsetToFirstChar > maxOffset) { throw new ArgumentOutOfRangeException("offsetToFirstChar", SR.Get(SRID.ParameterCannotBeGreaterThan, maxOffset)); } _charBuffer = charBuffer; _offsetToFirstChar = offsetToFirstChar; }
private string _CollectUntil(char[] stop, char[] disallowed) { CharacterBuffer buf = new CharacterBuffer(); while (true) { int cur = _reader.Read(); if (cur == -1) { throw new IOException(); } char ch = (char)cur; if (Array.IndexOf(stop, ch) >= 0) { break; } if (Array.IndexOf(disallowed, ch) >= 0) { throw new ApplicationException(); } buf.Write(ch); } return(buf.ToString()); }
private bool ReadDecodedCharactersUntilSentinel(CharacterBuffer buffer, char sentinel) { bool result = false; int startOffset = _DecodedCharacterOffset; while (_DecodedCharacterOffset < _DecodedCharacterCount) { if (_DecodedBuffer[_DecodedCharacterOffset++] == sentinel) { result = true; break; } } int charCount = _DecodedCharacterOffset - startOffset; if (result) { charCount -= 1; } buffer.Append(_DecodedBuffer, startOffset, charCount); return(result); }
/// <summary> /// Convenience method which calls <c>Fill(buffer, reader, buffer.Buffer.Length)</c>. </summary> public virtual bool Fill(CharacterBuffer buffer, TextReader reader) { return(Fill(buffer, reader, buffer.Buffer.Length)); }
/// <summary> /// Fills the <seealso cref="CharacterBuffer"/> with characters read from the given /// reader <seealso cref="Reader"/>. This method tries to read <code>numChars</code> /// characters into the <seealso cref="CharacterBuffer"/>, each call to fill will start /// filling the buffer from offset <code>0</code> up to <code>numChars</code>. /// In case code points can span across 2 java characters, this method may /// only fill <code>numChars - 1</code> characters in order not to split in /// the middle of a surrogate pair, even if there are remaining characters in /// the <seealso cref="Reader"/>. /// <para> /// Depending on the <seealso cref="Version"/> passed to /// <seealso cref="CharacterUtils#getInstance(Version)"/> this method implements /// supplementary character awareness when filling the given buffer. For all /// <seealso cref="Version"/> > 3.0 <seealso cref="#fill(CharacterBuffer, Reader, int)"/> guarantees /// that the given <seealso cref="CharacterBuffer"/> will never contain a high surrogate /// character as the last element in the buffer unless it is the last available /// character in the reader. In other words, high and low surrogate pairs will /// always be preserved across buffer boarders. /// </para> /// <para> /// A return value of <code>false</code> means that this method call exhausted /// the reader, but there may be some bytes which have been read, which can be /// verified by checking whether <code>buffer.getLength() > 0</code>. /// </para> /// </summary> /// <param name="buffer"> /// the buffer to fill. </param> /// <param name="reader"> /// the reader to read characters from. </param> /// <param name="numChars"> /// the number of chars to read </param> /// <returns> <code>false</code> if and only if reader.read returned -1 while trying to fill the buffer </returns> /// <exception cref="IOException"> /// if the reader throws an <seealso cref="IOException"/>. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public abstract boolean fill(CharacterBuffer buffer, java.io.Reader reader, int numChars) throws java.io.IOException; public abstract bool fill(CharacterBuffer buffer, Reader reader, int numChars);
public FormattedTextSymbols( GlyphingCache glyphingCache, TextRun textSymbols, bool rightToLeft, double scalingFactor, float pixelsPerDip, TextFormattingMode textFormattingMode, bool isSideways ) { _textFormattingMode = textFormattingMode; _isSideways = isSideways; ITextSymbols symbols = textSymbols as ITextSymbols; Debug.Assert(symbols != null); // break down a single text run into pieces IList <TextShapeableSymbols> shapeables = symbols.GetTextShapeableSymbols( glyphingCache, textSymbols.CharacterBufferReference, textSymbols.Length, rightToLeft, // This is a bool indicating the RTL // based on the bidi level of text (if applicable). // For FormattedTextSymbols it is equal to paragraph flow direction. rightToLeft, // This is the flow direction of the paragraph as // specified by the user. DWrite needs the paragraph // flow direction of the paragraph // while WPF algorithms need the RTL of the text based on // Bidi if possible. null, // cultureInfo null, // textModifierScope _textFormattingMode, _isSideways ); Debug.Assert(shapeables != null && shapeables.Count > 0); _rightToLeft = rightToLeft; _glyphs = new Glyphs[shapeables.Count]; CharacterBuffer charBuffer = textSymbols.CharacterBufferReference.CharacterBuffer; int offsetToFirstChar = textSymbols.CharacterBufferReference.OffsetToFirstChar; int i = 0; int ich = 0; while (i < shapeables.Count) { TextShapeableSymbols current = shapeables[i] as TextShapeableSymbols; Debug.Assert(current != null); int cch = current.Length; int j; // make a separate character buffer for glyphrun persistence char[] charArray = new char[cch]; for (j = 0; j < cch; j++) { charArray[j] = charBuffer[offsetToFirstChar + ich + j]; } if (current.IsShapingRequired) { ushort[] clusterMap; ushort[] glyphIndices; int[] glyphAdvances; GlyphOffset[] glyphOffsets; // unsafe { fixed(char *fixedCharArray = &charArray[0]) { MS.Internal.Text.TextInterface.TextAnalyzer textAnalyzer = MS.Internal.FontCache.DWriteFactory.Instance.CreateTextAnalyzer(); GlyphTypeface glyphTypeface = current.GlyphTypeFace; DWriteFontFeature[][] fontFeatures; uint[] fontFeatureRanges; uint unsignedCch = checked ((uint)cch); LSRun.CompileFeatureSet(current.Properties.TypographyProperties, unsignedCch, out fontFeatures, out fontFeatureRanges); textAnalyzer.GetGlyphsAndTheirPlacements( (ushort *)fixedCharArray, unsignedCch, glyphTypeface.FontDWrite, glyphTypeface.BlankGlyphIndex, false, // no sideway support yet /************************************************************************************************/ // rightToLeft, current.Properties.CultureInfo, /************************************************************************************************/ fontFeatures, fontFeatureRanges, current.Properties.FontRenderingEmSize, scalingFactor, pixelsPerDip, _textFormattingMode, current.ItemProps, out clusterMap, out glyphIndices, out glyphAdvances, out glyphOffsets ); } _glyphs[i] = new Glyphs( current, charArray, glyphAdvances, clusterMap, glyphIndices, glyphOffsets, scalingFactor ); } } else { // shaping not required, // bypass glyphing process altogether int[] nominalAdvances = new int[charArray.Length]; unsafe { fixed(char *fixedCharArray = &charArray[0]) fixed(int *fixedNominalAdvances = &nominalAdvances[0]) { current.GetAdvanceWidthsUnshaped( fixedCharArray, cch, scalingFactor, // format resolution specified per em, fixedNominalAdvances ); } } _glyphs[i] = new Glyphs( current, charArray, nominalAdvances, scalingFactor ); } i++; ich += cch; } }
public ReadToEndThunk() { Buffer = new CharacterBuffer(); OnDecodeComplete = _OnDecodeComplete; }
static internal int GetChar( CharacterBuffer charBuffer, int ichText, int cchText, int charNumber, out int wordCount) { if (charNumber < cchText-1 && ((charBuffer[ichText + charNumber] & 0xFC00) == 0xD800) && ((charBuffer[ichText + charNumber+1] & 0xFC00) == 0xDC00)) { wordCount = 2; return ((((charBuffer[ichText + charNumber] & 0x03ff) << 10) | (charBuffer[ichText + charNumber+1] & 0x3ff)) + 0x10000); } wordCount = 1; return ((int) charBuffer[ichText + charNumber]); }
static internal bool BidiAnalyzeInternal( CharacterBuffer charBuffer, // character buffer int ichText, // offset to first char in the buffer int cchText, // number of input char int cchTextMaxHint, // hint maximum number of char processed Flags flags, // control flags State state, // bidi state in, out or both IList<byte> levels, // [IN/OUT] resolved level per char IList<DirectionClass> characterClass, // [IN/OUT] direction class of each char out int cchResolved // number of char resolved ) { DirectionClass tempClass; int [] runLimits; State stateIn = null, stateOut = null; // both can point into state parameter ulong overrideStatus; OverrideClass overrideClass; ushort stackOverflow; byte baseLevel; byte lastRunLevel; byte lastNonBnLevel; int counter; int codePoint; int lengthUnresolved = 0; int controlStack = 0; int runCount = 0; int wordCount; Invariant.Assert(levels != null && levels.Count >= cchText); Invariant.Assert(characterClass != null && characterClass.Count >= cchText); cchResolved = 0; // Verifying input parameters. if(charBuffer == null || (cchText <= 0) || (charBuffer.Count < cchText) || ((((flags & Flags.ContinueAnalysis)!=0) || ((flags & Flags.IncompleteText)!=0)) && (state == null))) { return false; } // try to be smart to get the maximum we need to process. if ((flags & Flags.MaximumHint) != 0 && cchTextMaxHint>0 && cchTextMaxHint < cchText) { if (cchTextMaxHint>1 && (charBuffer[ichText + cchTextMaxHint-2] & 0xFC00) == 0xD800) { // it might be surrogate pair cchTextMaxHint--; } int index = cchTextMaxHint-1; int intChar = charBuffer[ichText + index]; wordCount = 1; if ((intChar & 0xFC00) == 0xD800) { intChar = DoubleWideChar.GetChar(charBuffer, ichText, cchText, index, out wordCount); } tempClass = Classification.CharAttributeOf((int) Classification.GetUnicodeClass(intChar)).BiDi; index += wordCount; if (CharProperty[1, (int) tempClass]==1) { // if we got more than 20 same strong charcaters class, we give up. we might // get this case with Thai script. while (index<cchText && index-cchTextMaxHint<20) { intChar = charBuffer[ichText + index]; wordCount = 1; if ((intChar & 0xFC00) == 0xD800) { intChar = DoubleWideChar.GetChar(charBuffer, ichText, cchText, index, out wordCount); } if (tempClass != Classification.CharAttributeOf((int) Classification.GetUnicodeClass(intChar)).BiDi) { break; } else { index += wordCount; } } } else { // we got neutral try to get first strong character. while (index<cchText) { intChar = charBuffer[ichText + index]; wordCount = 1; if ((intChar & 0xFC00) == 0xD800) { intChar = DoubleWideChar.GetChar(charBuffer, ichText, cchText, index, out wordCount); } if (CharProperty[1, (int) Classification.CharAttributeOf((int) Classification.GetUnicodeClass(intChar)).BiDi] == 1) break; index += wordCount; } index++; // include the first strong character to be able to resolve the neutrals } cchText = Math.Min(cchText, index); } // If the last character in the string is a paragraph terminator, // we can analyze the whole string, No need to use state parameter // for output BidiStack levelsStack = new BidiStack(); if ((flags & Flags.IncompleteText) != 0) { codePoint = charBuffer[ichText + cchText -1]; if((cchText > 1) && ((charBuffer[ichText + cchText -2] & 0xFC00 ) == 0xD800) && ((charBuffer[ichText + cchText - 1] & 0xFC00) == 0xDC00)) { codePoint = 0x10000 + (((charBuffer[ichText + cchText -2] & 0x3ff) << 10) | (charBuffer[ichText + cchText - 1] & 0x3ff)); } if (DirectionClass.ParagraphSeparator != Classification.CharAttributeOf((int) Classification.GetUnicodeClass(codePoint)).BiDi) { stateOut = state; } } if ((flags & Flags.ContinueAnalysis) != 0) { // try to see if we have enough information to start the analysis or we need to get more. codePoint = charBuffer[ichText + 0]; if((cchText > 1) && ((charBuffer[ichText + 0] & 0xFC00 ) == 0xD800) && ((charBuffer[ichText + 1] & 0xFC00) == 0xDC00)) { codePoint = 0x10000 + (((charBuffer[ichText + 0] & 0x3ff) << 10) | (charBuffer[ichText + 1] & 0x3ff)); } tempClass = Classification.CharAttributeOf((int) Classification.GetUnicodeClass(codePoint)).BiDi; // state can be used as in/out parameter stateIn = state; // Note: use the state instant to call LastStrongClass or LastStrongOrNumberClass // which should be overrided by the caller. switch (tempClass) { case DirectionClass.Left: case DirectionClass.Right: case DirectionClass.ArabicNumber: case DirectionClass.ArabicLetter: stateIn.LastNumberClass = tempClass; stateIn.LastStrongClass = tempClass; break; case DirectionClass.EuropeanNumber: stateIn.LastNumberClass = tempClass; break; } } // Done with the state if (stateIn != null) { if (!levelsStack.Init(stateIn.LevelStack)) { cchResolved = 0; return false; } baseLevel = levelsStack.GetCurrentLevel(); stackOverflow = stateIn.Overflow; overrideStatus = stateIn.OverrideLevels; overrideClass = (Helper.IsBitSet(overrideStatus, baseLevel)) ? (Helper.IsOdd(baseLevel) ? OverrideClass.OverrideClassRight : OverrideClass.OverrideClassLeft): OverrideClass.OverrideClassNeutral; } else { baseLevel = BaseLevelLeft; if ((flags & Flags.FirstStrongAsBaseDirection) != 0) { // Find strong character in the first paragraph // This might cause a complete pass over the input string // but we must get it before we start. DirectionClass firstStrong = DirectionClass.ClassInvalid; if (GetFirstStrongCharacter(charBuffer, ichText, cchText, ref firstStrong)) { if (firstStrong != DirectionClass.Left) { baseLevel = BaseLevelRight; } } } else if ((flags & Flags.DirectionRightToLeft) != 0) { baseLevel = BaseLevelRight; } levelsStack.Init((ulong) baseLevel + 1); stackOverflow = 0; // Initialize to neutral overrideStatus = 0; overrideClass = OverrideClass.OverrideClassNeutral; } byte paragraphEmbeddingLevel = levelsStack.GetStackBottom(); // // try to optimize through a fast path. // int neutralIndex = -1; byte bidiLevel, nonBidiLevel; byte lastPathClass; byte basePathClass; byte neutralLevel; DirectionClass lastStrongClass; if (Helper.IsOdd(baseLevel)) { bidiLevel = baseLevel; nonBidiLevel = (byte) (baseLevel + 1); lastPathClass = basePathClass = 3; if (stateIn != null ) lastStrongClass = stateIn.LastStrongClass; else lastStrongClass = DirectionClass.Right; } else { nonBidiLevel = baseLevel; bidiLevel = (byte) (baseLevel + 1); lastPathClass = basePathClass = 2; if (stateIn != null ) lastStrongClass = stateIn.LastStrongClass; else lastStrongClass = DirectionClass.Left; } if (stateIn != null ) { if ((FastPathClass[(int) lastStrongClass] & 0x02) == 0x02) // Strong Left or Right { lastPathClass = FastPathClass[(int) lastStrongClass]; } } // // Hidden text do not affect the relative order of surrounding text. We do that by // assigning them to the class type of either the preceding or following non-hidden text // so that they won't cause additional transitions of Bidi levels. // DirectionClass hiddenCharClass = DirectionClass.GenericNeutral; counter = 0; wordCount = 1; // In case the input starts with hidden characters, we will assign them to the class of the following // non-hidden cp. The for-loop scans forward till the 1st non-hidden cp and remembers its bidi class // to be used in case there are hidden cp at the beginning of the input. for (int i = counter; i < cchText; i += wordCount) { int intChar = charBuffer[ichText + i]; if ((intChar & 0xFC00) == 0xD800) { intChar = DoubleWideChar.GetChar(charBuffer, ichText, cchText, counter, out wordCount); } if (intChar != CharHidden) { hiddenCharClass = Classification.CharAttributeOf((int)Classification.GetUnicodeClass(intChar)).BiDi; if ( hiddenCharClass == DirectionClass.EuropeanNumber && (flags & Flags.OverrideEuropeanNumberResolution) != 0) { hiddenCharClass = characterClass[i]; // In case EN resolution is overridden. } break; } } while (counter < cchText) { // Account for surrogate characters wordCount = 1; codePoint = DoubleWideChar.GetChar(charBuffer, ichText, cchText, counter, out wordCount); tempClass = Classification.CharAttributeOf((int) Classification.GetUnicodeClass(codePoint)).BiDi; if (codePoint == CharHidden) { tempClass = hiddenCharClass; } if (FastPathClass[(int) tempClass] == 0) break; // The directional class can be processed in fast path. It will not be EN or AN and hence not // overridable. characterClass[counter] = tempClass; hiddenCharClass = tempClass; if (FastPathClass[(int) tempClass] == 1) // Neutral { if (tempClass != DirectionClass.EuropeanSeparator && tempClass != DirectionClass.CommonSeparator) characterClass[counter] = DirectionClass.GenericNeutral; if (neutralIndex == -1) neutralIndex = counter; } else // strong class (2, 3, or 4) { if (neutralIndex != -1) // resolve the neutral { if (lastPathClass != FastPathClass[(int) tempClass]) { neutralLevel = baseLevel; } else { neutralLevel = lastPathClass == 2 ? nonBidiLevel : bidiLevel; } while (neutralIndex < counter) { levels[neutralIndex] = neutralLevel; neutralIndex++; } neutralIndex = -1; } lastPathClass = FastPathClass[(int) tempClass]; levels[counter] = lastPathClass == 2 ? nonBidiLevel : bidiLevel; if (wordCount == 2) { // Higher and Lower surrogate should have the same bidi level. levels[counter + 1] = levels[counter]; } lastStrongClass = tempClass; } counter = counter + wordCount; } if (counter < cchText) // couldn't optimize. { // reset the levels for (int j=0; j<counter; j++) levels[j] = baseLevel; } else { cchResolved = cchText; if (state != null) { state.LastStrongClass = lastStrongClass; } if (neutralIndex != -1) // resolve the neutral { if ((flags & Flags.IncompleteText) == 0) { if (lastPathClass != basePathClass) { neutralLevel = baseLevel; } else { neutralLevel = lastPathClass == 2 ? nonBidiLevel : bidiLevel; } while (neutralIndex < cchText) { levels[neutralIndex] = neutralLevel; neutralIndex++; } } else { cchResolved = neutralIndex; } } return true; } // // end fast path // // Get character classifications. // Resolve explicit embedding levels. // Record run limits (either due to a level change or due to new paragraph) lastNonBnLevel = baseLevel; // for the worst case of all paragraph terminators string. runLimits = new int[cchText]; // counter is already initialized in the fast path while (counter < cchText) { int intChar = charBuffer[ichText + counter]; wordCount = 1; if ((intChar & 0xFC00) == 0xD800) { intChar = DoubleWideChar.GetChar(charBuffer, ichText, cchText, counter, out wordCount); } DirectionClass currentClass; currentClass = Classification.CharAttributeOf((int) Classification.GetUnicodeClass(intChar)).BiDi; levels[counter] = levelsStack.GetCurrentLevel(); if (intChar == CharHidden) { currentClass = hiddenCharClass; } switch(currentClass) { case DirectionClass.ParagraphSeparator: // mark output level array with a special mark // to seperate between paragraphs levels[counter] = ParagraphTerminatorLevel; runLimits[runCount] = counter; if (counter != cchText-1) { runCount++; } levelsStack.Init((ulong) baseLevel + 1); overrideStatus = 0; overrideClass = OverrideClass.OverrideClassNeutral; stackOverflow = 0; controlStack = 0; goto case DirectionClass.OtherNeutral; // Fall through // We keep our Unicode classification table stictly following Unicode // regarding neutral types (B, S, WS, ON), change all to generic N. case DirectionClass.SegmentSeparator: case DirectionClass.WhiteSpace: case DirectionClass.OtherNeutral: characterClass[counter] = DirectionClass.GenericNeutral; if (counter>0 && characterClass[counter-1] == DirectionClass.BoundaryNeutral) { if (levels[counter-1] < levels[counter] && levels[counter] != ParagraphTerminatorLevel) { levels[counter-1] = levels[counter]; } } controlStack = 0; break; case DirectionClass.LeftToRightEmbedding: case DirectionClass.RightToLeftEmbedding: characterClass[counter] = DirectionClass.BoundaryNeutral; if ((flags & Flags.IgnoreDirectionalControls) != 0) break; // Ignore directional controls. They won't affect bidi state // If we overflowed the stack, keep track of this in order to know when you hit // a PDF if you should pop or not. if(!levelsStack.Push(currentClass == DirectionClass.LeftToRightEmbedding ? true : false)) { stackOverflow++; } else { runLimits[runCount] = counter; if (counter != cchText-1) { runCount++; } controlStack++; } overrideClass = OverrideClass.OverrideClassNeutral; levels[counter] = lastNonBnLevel; break; case DirectionClass.LeftToRightOverride: case DirectionClass.RightToLeftOverride: characterClass[counter] = DirectionClass.BoundaryNeutral; if ((flags & Flags.IgnoreDirectionalControls) != 0) break; // Ignore directional controls. They won't affect bidi state if(!levelsStack.Push(currentClass == DirectionClass.LeftToRightOverride ? true : false)) { stackOverflow++; } else { // Set the matching bit of 'overrideStatus' to one // in order to know when you pop if you're in override state or not. Helper.ResetBit(ref overrideStatus, levelsStack.GetCurrentLevel()); overrideClass = (currentClass == DirectionClass.LeftToRightOverride) ? OverrideClass.OverrideClassLeft : OverrideClass.OverrideClassRight; runLimits[runCount] = counter; if (counter != cchText-1) { runCount++; } controlStack++; } levels[counter] = lastNonBnLevel; break; case DirectionClass.PopDirectionalFormat: characterClass[counter] = DirectionClass.BoundaryNeutral; if ((flags & Flags.IgnoreDirectionalControls) != 0) break; // Ignore directional controls. They won't affect bidi state if (stackOverflow != 0) { stackOverflow--; } else { if (levelsStack.Pop()) { int newLevel = levelsStack.GetCurrentLevel(); // Override state being left or right is determined // from the new level being even or odd. overrideClass = (Helper.IsBitSet(overrideStatus, newLevel)) ? (Helper.IsOdd(newLevel) ? OverrideClass.OverrideClassRight : OverrideClass.OverrideClassLeft): OverrideClass.OverrideClassNeutral; if (controlStack > 0) { runCount--; controlStack--; } else { runLimits[runCount] = counter; if (counter != cchText-1) { runCount++; } } } } levels[counter] = lastNonBnLevel; break; default: controlStack = 0; if ( currentClass == DirectionClass.EuropeanNumber && (flags & Flags.OverrideEuropeanNumberResolution) != 0) { // Use the input DirectionClass explictly for EN. We don't // need to copy the the Unicode classification data into it. // However, assert that the input DirectionClass must be either be AN or EN Invariant.Assert(characterClass[counter] == DirectionClass.ArabicNumber || characterClass[counter] == DirectionClass.EuropeanNumber); } else { // Non EuropeanNumber is not affected by the input DirectionClass. characterClass[counter] = currentClass; } if(overrideClass != OverrideClass.OverrideClassNeutral) { characterClass[counter] = (overrideClass == OverrideClass.OverrideClassLeft) ? DirectionClass.Left : DirectionClass.Right; } if (counter>0 && characterClass[counter-1]==DirectionClass.BoundaryNeutral) { if (levels[counter-1] < levels[counter]) { levels[counter-1] = levels[counter]; } } break; } lastNonBnLevel = levels[counter]; if (wordCount > 1) { levels[counter+1] = levels[counter]; characterClass[counter+1] = characterClass[counter]; } hiddenCharClass = characterClass[counter]; counter += wordCount; } runCount++; if (stateOut != null) { stateOut.LevelStack = levelsStack.GetData(); stateOut.OverrideLevels = overrideStatus; stateOut.Overflow = stackOverflow; } // Resolve neutral and weak types. // Resolve implict levels. // The lastRunLevel will hold the level of last processed run to be used // to determine the sor of the next run. we can't depend on the level array // because it can be changed in case of numerics. so level of the numerics // will be increased by one or two. lastRunLevel = baseLevel; bool currenLimitIsParagraphTerminator; bool previousLimitIsParagraphTerminator = false; for(counter = 0; counter < runCount; counter++) { DirectionClass sor; DirectionClass eor; currenLimitIsParagraphTerminator = (levels[runLimits[counter]] == ParagraphTerminatorLevel); if (currenLimitIsParagraphTerminator) levels[runLimits[counter]] = baseLevel; int runStart = (counter == 0) ? 0 : runLimits[counter - 1] + 1; // If the level transition was due to a new paragraph // we don't want pass the paragraph terminator position. int offset = (counter != (runCount - 1)) ? (currenLimitIsParagraphTerminator ? 1 : 0) : 0; int runLength = (counter == (runCount - 1)) ? (int) ((cchText - runStart) - offset): (int) (runLimits[counter] - runStart) + 1 - offset; // See if we need to provide state information from a previous call // or need to save it for a possible next call bool incompleteRun = ((runCount - 1) == counter) && ((flags & Flags.IncompleteText) != 0) && (stateOut != null); bool continuingAnalysis = (counter == 0) && (stateIn != null); int runLengthResolved; // First run or a run after paragraph terminator. if ((counter == 0) || previousLimitIsParagraphTerminator) { sor = Helper.IsOdd(Math.Max(baseLevel, levels[runStart])) ? DirectionClass.Right : DirectionClass.Left; } else { sor = Helper.IsOdd(Math.Max(lastRunLevel, levels[runStart])) ? DirectionClass.Right : DirectionClass.Left; } lastRunLevel = levels[runStart]; // Last run or a run just before paragraph terminator. if( ((runCount - 1) == counter) || currenLimitIsParagraphTerminator) { eor = Helper.IsOdd(Math.Max(levels[runStart], baseLevel)) ? DirectionClass.Right : DirectionClass.Left; } else { // we will try to get first run which doesn't have just one // control char like LRE,RLE,... and so on int runNumber = counter+1; while ( runNumber<runCount - 1 && runLimits[runNumber]-runLimits[runNumber-1]==1 && characterClass[runLimits[runNumber]] == DirectionClass.BoundaryNeutral) { runNumber++; } eor = Helper.IsOdd(Math.Max(levels[runStart], levels[runLimits[runNumber-1] + 1])) ? DirectionClass.Right : DirectionClass.Left; } // If it is a continuation from a previous call, set sor // to the last stron type saved in the input state parameter. runLengthResolved = ResolveNeutralAndWeak(characterClass, runStart, runLength, sor, eor, levels[runStart], continuingAnalysis ? stateIn: null, incompleteRun ? stateOut: null, ((counter == 0) && (stateIn == null)) ? ((flags & Flags.PreviousStrongIsArabic)!=0): false, flags); if (!incompleteRun) { // If we in a complete run, we should be able to resolve everything // unless we passed a corrupted data Debug.Assert(runLengthResolved == runLength, "Failed to resolve neutrals and weaks. Run#:" + counter.ToString(CultureInfo.InvariantCulture)); } else { lengthUnresolved = (runLength - runLengthResolved); } // Resolve implict levels. // Also, takes care of Rule L1 (segment separators, paragraph separator, // white spaces at the end of the line. ResolveImplictLevels(characterClass, charBuffer, ichText, runLength - lengthUnresolved, levels, runStart, paragraphEmbeddingLevel); previousLimitIsParagraphTerminator = currenLimitIsParagraphTerminator; } cchResolved = cchText - lengthUnresolved; // if the charBuffer ended with paragraph seperator then we need to reset the Bidi state if (((flags & Flags.IncompleteText) != 0) && (stateOut == null)) { state.OverrideLevels = 0; state.Overflow = 0; if ((paragraphEmbeddingLevel & 1) != 0) { state.LastStrongClass = DirectionClass.Right; state.LastNumberClass = DirectionClass.Right; state.LevelStack = Bidi.StackRtl; } else { state.LastStrongClass = DirectionClass.Left; state.LastNumberClass = DirectionClass.Left; state.LevelStack = Bidi.StackLtr; } } return true; }
/// <summary> /// Convenience method which calls <code>fill(buffer, reader, buffer.buffer.length)</code>. </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public final boolean fill(CharacterBuffer buffer, java.io.Reader reader) throws java.io.IOException public bool fill(CharacterBuffer buffer, Reader reader) { return(fill(buffer, reader, buffer.buffer.Length)); }
private Token _GetToken() { Token result = new Token(); int cur = _reader.Read(); if (cur == -1) { result._characterClass = CharacterClass.EndOfFile; return(result); } char ch = (char)cur; CharacterClass cc = _settings.Classifier [ch]; CharacterBuffer cb = new CharacterBuffer(); cb.Write(ch); switch (cc) { case CharacterClass.Whitespace: result._characterClass = CharacterClass.Whitespace; result._value = _Collect(CharacterClass.Whitespace, ch); if (_settings.SkipWhiteSpace) { return(_GetToken()); } break; case CharacterClass.Quote: result._characterClass = CharacterClass.Quote; result._value = _CollectUntil (new char[] { ch }, new char[] { '\n' }); break; case CharacterClass.Comment: result._characterClass = CharacterClass.Comment; result._value = _CollectUntil (new char[] { '\n' }, new char[0]); break; case CharacterClass.Digit: result._characterClass = CharacterClass.Digit; result._value = _Collect(CharacterClass.Digit, ch); break; case CharacterClass.Punctuation: result._characterClass = CharacterClass.Punctuation; result._value = new string ( ch, 1 ); break; case CharacterClass.Word: result._characterClass = CharacterClass.Word; result._value = _Collect(CharacterClass.Word, ch); break; case CharacterClass.EndOfFile: result._characterClass = CharacterClass.EndOfFile; break; } return(result); }
public void BufferCharacter([FromBody] CharacterBuffer buff) { buffer = buff; }
private const int MaxLevel = 63; // right to left // // Start BiDi class implementation // static private bool GetFirstStrongCharacter( CharacterBuffer charBuffer, int ichText, int cchText, ref DirectionClass strongClass) { DirectionClass currentClass = DirectionClass.ClassInvalid; int counter = 0; int wordCount; while (counter<cchText) { int intChar = charBuffer[ichText + counter]; wordCount = 1; if ((intChar & 0xFC00) == 0xD800) { intChar = DoubleWideChar.GetChar(charBuffer, ichText, cchText, counter, out wordCount); } currentClass = Classification.CharAttributeOf((int) Classification.GetUnicodeClass(intChar)).BiDi; if (CharProperty[0, (int) currentClass]==1 || currentClass == DirectionClass.ParagraphSeparator) { break; } counter += wordCount; } if (CharProperty[0, (int) currentClass]==1) { strongClass = currentClass; return true; } return false; }
/// <summary> /// Fills the <see cref="CharacterBuffer"/> with characters read from the given /// reader <see cref="TextReader"/>. This method tries to read <code>numChars</code> /// characters into the <see cref="CharacterBuffer"/>, each call to fill will start /// filling the buffer from offset <c>0</c> up to <paramref name="numChars"/>. /// In case code points can span across 2 java characters, this method may /// only fill <c>numChars - 1</c> characters in order not to split in /// the middle of a surrogate pair, even if there are remaining characters in /// the <see cref="TextReader"/>. /// <para> /// Depending on the <see cref="LuceneVersion"/> passed to /// <see cref="CharacterUtils.GetInstance(LuceneVersion)"/> this method implements /// supplementary character awareness when filling the given buffer. For all /// <see cref="LuceneVersion"/> > 3.0 <see cref="Fill(CharacterBuffer, TextReader, int)"/> guarantees /// that the given <see cref="CharacterBuffer"/> will never contain a high surrogate /// character as the last element in the buffer unless it is the last available /// character in the reader. In other words, high and low surrogate pairs will /// always be preserved across buffer boarders. /// </para> /// <para> /// A return value of <c>false</c> means that this method call exhausted /// the reader, but there may be some bytes which have been read, which can be /// verified by checking whether <c>buffer.Length > 0</c>. /// </para> /// </summary> /// <param name="buffer"> /// the buffer to fill. </param> /// <param name="reader"> /// the reader to read characters from. </param> /// <param name="numChars"> /// the number of chars to read </param> /// <returns> <code>false</code> if and only if reader.read returned -1 while trying to fill the buffer </returns> /// <exception cref="IOException"> /// if the reader throws an <see cref="IOException"/>. </exception> public abstract bool Fill(CharacterBuffer buffer, TextReader reader, int numChars);
/// <summary> /// Fills the <seealso cref="CharacterBuffer"/> with characters read from the given /// reader <seealso cref="Reader"/>. This method tries to read <code>numChars</code> /// characters into the <seealso cref="CharacterBuffer"/>, each call to fill will start /// filling the buffer from offset <code>0</code> up to <code>numChars</code>. /// In case code points can span across 2 java characters, this method may /// only fill <code>numChars - 1</code> characters in order not to split in /// the middle of a surrogate pair, even if there are remaining characters in /// the <seealso cref="Reader"/>. /// <para> /// Depending on the <seealso cref="LuceneVersion"/> passed to /// <seealso cref="CharacterUtils#getInstance(Version)"/> this method implements /// supplementary character awareness when filling the given buffer. For all /// <seealso cref="LuceneVersion"/> > 3.0 <seealso cref="#fill(CharacterBuffer, Reader, int)"/> guarantees /// that the given <seealso cref="CharacterBuffer"/> will never contain a high surrogate /// character as the last element in the buffer unless it is the last available /// character in the reader. In other words, high and low surrogate pairs will /// always be preserved across buffer boarders. /// </para> /// <para> /// A return value of <code>false</code> means that this method call exhausted /// the reader, but there may be some bytes which have been read, which can be /// verified by checking whether <code>buffer.getLength() > 0</code>. /// </para> /// </summary> /// <param name="buffer"> /// the buffer to fill. </param> /// <param name="reader"> /// the reader to read characters from. </param> /// <param name="numChars"> /// the number of chars to read </param> /// <returns> <code>false</code> if and only if reader.read returned -1 while trying to fill the buffer </returns> /// <exception cref="IOException"> /// if the reader throws an <seealso cref="IOException"/>. </exception> public abstract bool Fill(CharacterBuffer buffer, Reader reader, int numChars);
static public int AdvanceUntilUTF16( CharacterBuffer charBuffer, int offsetToFirstChar, int stringLength, ushort mask, out ushort charFlags ) { int i = offsetToFirstChar; int limit = offsetToFirstChar + stringLength; charFlags = 0; while (i < limit) { unsafe { ushort flags = (ushort)Classification.CharAttributeTable[(int)GetUnicodeClassUTF16(charBuffer[i])].Flags; if((flags & mask) != 0) break; charFlags |= flags; } i++; } return i - offsetToFirstChar; }
public override bool Fill(CharacterBuffer buffer, Reader reader, int numChars) { Debug.Assert(buffer.buffer.Length >= 2); if (numChars < 2 || numChars > buffer.buffer.Length) { throw new System.ArgumentException("numChars must be >= 2 and <= the buffer size"); } char[] charBuffer = buffer.buffer; buffer.offset = 0; int offset; // Install the previously saved ending high surrogate: if (buffer.lastTrailingHighSurrogate != 0) { charBuffer[0] = buffer.lastTrailingHighSurrogate; buffer.lastTrailingHighSurrogate = (char)0; offset = 1; } else { offset = 0; } int read = ReadFully(reader, charBuffer, offset, numChars - offset); buffer.length = offset + read; bool result = buffer.length == numChars; if (buffer.length < numChars) { // We failed to fill the buffer. Even if the last char is a high // surrogate, there is nothing we can do return result; } if (char.IsHighSurrogate(charBuffer[buffer.length - 1])) { buffer.lastTrailingHighSurrogate = charBuffer[--buffer.length]; } return result; }
public Character(CharacterBuffer buffer) : this(buffer, false) { }
static private void ResolveImplictLevels( IList<DirectionClass> characterClass, // [IN / OUT] CharacterBuffer charBuffer, // [IN] int ichText, // [IN] int runLength, // [IN] IList<byte> levels, // [IN / OUT] int index, byte paragraphEmbeddingLevel // [IN] Paragraph base level ) { if (runLength == 0) { return; } int counter = 0; for (counter = runLength -1; counter >= 0; counter--) { Invariant.Assert(CharProperty[3, (int) characterClass[counter+index]]==1, ("Cannot have unresolved classes during implict levels resolution")); int intChar = charBuffer[ichText + index+counter]; int wordCount = 1; if (((intChar & 0xFC00) == 0xDC00) && counter > 0) { if ((charBuffer[ichText + index+counter-1] & 0xFC00) == 0xD800) { intChar = ((((charBuffer[ichText + index+counter-1] & 0x03ff) << 10) | (charBuffer[ichText + index+counter] & 0x3ff)) + 0x10000); wordCount = 2; } } DirectionClass directionClass; directionClass = Classification.CharAttributeOf((int) Classification.GetUnicodeClass(intChar)).BiDi; if (directionClass == DirectionClass.ParagraphSeparator || directionClass == DirectionClass.SegmentSeparator) { // Rule L1: segment separator and paragraph separator should use paragraph embedding level levels[counter+index] = paragraphEmbeddingLevel; } else { levels[counter+index] = (byte)((ImplictPush[Helper.IsOdd(levels[counter+index]) ? 1 : 0, (int)characterClass[index+counter]]) + levels[counter+index]); } if (wordCount > 1) { levels[counter+index-1] = levels[counter+index]; counter--; } } }
/// <summary> /// Convenience method which calls <code>fill(buffer, reader, buffer.buffer.length)</code>. </summary> public virtual bool Fill(CharacterBuffer buffer, Reader reader) { return Fill(buffer, reader, buffer.buffer.Length); }
private bool ReadDecodedCharactersUntilSentinel(CharacterBuffer buffer, char sentinel) { bool result = false; int startOffset = _DecodedCharacterOffset; while (_DecodedCharacterOffset < _DecodedCharacterCount) { if (_DecodedBuffer[_DecodedCharacterOffset++] == sentinel) { result = true; break; } } int charCount = _DecodedCharacterOffset - startOffset; if (result) charCount -= 1; buffer.Append(_DecodedBuffer, startOffset, charCount); return result; }
public override bool Fill(CharacterBuffer buffer, Reader reader, int numChars) { Debug.Assert(buffer.buffer.Length >= 1); if (numChars < 1 || numChars > buffer.buffer.Length) { throw new System.ArgumentException("numChars must be >= 1 and <= the buffer size"); } buffer.offset = 0; int read = ReadFully(reader, buffer.buffer, 0, numChars); buffer.length = read; buffer.lastTrailingHighSurrogate = (char)0; return read == numChars; }