Пример #1
0
        public static Token? TryMatch(CharBuffer cs)
        {
            if (!cs.TryExpect(StringTag)) { return null; }

            var errPos = cs.FilePosition;

            StringBuilder sb = new StringBuilder(64);
            sb.Append(cs.Consume(StringTag.Length).ToArray());

            while (!cs.TryExpect(StringTag))
            {
                if (cs.End)
                {
                    break;
                }

                if (cs.TryExpect('\\'))
                {
                    sb.Append(cs.Consume());
                }

                sb.Append(cs.Consume());
            }

            if (!cs.TryExpect(StringTag))
            {
                throw Parser.CreateParseError(errPos, Constants.ParseErrorStringNotClosed);
            }
            else
            {
                sb.Append(cs.Consume(3).ToArray());
                return new Token(TokenType.MultilineString, sb.ToString());
            }
        }
Пример #2
0
        public void CanReadCompleContent()
        {
            // Arrange
            var content = "This is";
            var sb = new StringBuilder();
            var sr = new StreamReader(content.ToStream());
            var lab = new CharBuffer(() =>
            {
                int read = sr.Read();
                return read != -1 ? new char?((char)read) : new char?();
            }, 3);

            // Act

            while (lab.HasNext())
            {
                sb.Append(lab.PeekAt(0));
                lab.Consume();
            }

            sb.Append(lab.PeekAt(0));

            // Assert
            sb.ToString().Should().Be(content);
        }
Пример #3
0
        internal static Token? TryMatch(CharBuffer cs)
        {
            StringBuilder sb = new StringBuilder(256);
            if (!cs.TryExpect(StringTag))
            {
                return null;
            }

            var errPos = cs.FilePosition;

            if (cs.TryExpectAt(1, StringTag) && cs.TryExpectAt(2, StringTag))
            {
                return MultilineLiteralStringMatcher.TryMatch(cs);
            }

            sb.Append(cs.Consume());

            while (!cs.End && !cs.TryExpect(StringTag))
            {
                sb.Append(cs.Consume());
            }

            if (!cs.TryExpect(StringTag))
            {
                throw Parser.CreateParseError(errPos, Constants.ParseErrorStringNotClosed);
            }
            else
            {
                sb.Append(cs.Consume());
                return new Token(TokenType.LiteralString, sb.ToString());
            }
        }
Пример #4
0
        private static void SerializeCustomer(CharBuffer b, Marlee.Jsv.Console.Program.Customer c)
        {
            b.Write('{');
              if (c.Name != null)
              {
            b.Write("Name:");
            WriteString(b, c.Name);
            b.Write(',');
              }
              b.Write("ID:");
              b.Write(c.ID);
              b.Write(',');

              if (c.Roles != null)
              {
            b.Write("Roles:[");
            for (var i = 0; i < c.Roles.Count; i++)
            {
              WriteString(b, c.Roles[i]);
              b.Write(']');
            }
            b.Write(']');
            b.Write(',');
              }

              if (c.Address != null)
              {
            SerializeAddress(b, c.Address);
            b.Write(',');
              }

              if (c.PhoneNumbers != null)
              {
            b.Write("PhoneNumbers:[");
            for (var i = 0; i < c.PhoneNumbers.Count; i++)
            {
              SerializePhoneNumber(b, c.PhoneNumbers[i]);
            }
            b.Write(']');
            b.Write(',');
              }

              if (c.FirstName != null)
              {
            b.Write("FirstName:");
            WriteString(b, c.FirstName);
            b.Write(',');
              }

              if (c.LastName != null)
              {
            b.Write("LastName:");
            WriteString(b, c.LastName);
            b.Write(',');
              }

              b.Write("Age:");
              b.Write(c.Age);
              b.Write('}');
        }
Пример #5
0
 private char CheckStyle(CharBuffer buffer)
 {
     return IsStyle(buffer, S1) ? S1 :
         IsStyle(buffer, S2) ? S2 :
         IsStyle(buffer, S3) ? S3 :
         IsStyle(buffer, S4) ? S4 :
         NIL;
 }
Пример #6
0
 public static string replace(string str, string swap, int start, int count)
 {
     int capacity = (str.Length + swap.Length) - count;
     CharBuffer buffer = new CharBuffer(capacity);
     buffer.append(str.Substring(0, start)).append(swap);
     buffer.append(str.Substring(start + count));
     return buffer.getString();
 }
Пример #7
0
 public static string replace(string str, string swap, int start, int count, CharBuffer cb)
 {
     int len = (str.Length + swap.Length) - count;
     cb.clear();
     cb.setCapacity(len);
     cb.append(str.Substring(0, start)).append(swap);
     cb.append(str.Substring(start + count));
     return cb.getString();
 }
Пример #8
0
        public IEnumerable<StyledToken> Parse(string source)
        {
            var buffer = new CharBuffer(source);
            var spacePos = 0;

            while (buffer.MoveNext())
            {
                var c = buffer.GetCurrent();

                if (c == SL && Hyperlinks)
                {
                    if (buffer.GetNext() == SL && buffer.GetPrevious() == DD && spacePos > -1)
                    {
                        var sp = spacePos > 0 ? spacePos + 1 : spacePos;
                        var ep = buffer.Offset - 2;
                        var str = buffer.GetString(sp, ep - sp + 1);

                        while (!IsEmptyOrBrace(buffer.GetNext()))
                            buffer.MoveNext();

                        yield return new StyledToken(sp, buffer.Offset - sp + 1, TextStyle.Hyperlink);

                        spacePos = buffer.Offset;
                    }
                }
                else if (c == BS && Bold && IsStart(buffer))
                {
                    var a = buffer.SetAnchor();

                    while (!IsEmpty(buffer.GetNext()))
                        buffer.MoveNext();

                    if (buffer.GetCurrent() != BS)
                        buffer.BackToAnchor();
                    else
                        yield return new StyledToken(a, buffer.Offset - a + 1, TextStyle.Style1);
                }
                else if (c == IS && Italic && IsStart(buffer))
                {
                    var a = buffer.SetAnchor();

                    while (!IsEmpty(buffer.GetNext()))
                        buffer.MoveNext();

                    if (buffer.GetCurrent() != IS)
                        buffer.BackToAnchor();
                    else
                        yield return new StyledToken(a, buffer.Offset - a + 1, TextStyle.Style2);
                }
                else if (IsSep(c))
                    spacePos = buffer.Offset;
            }
        }
Пример #9
0
	  protected internal override CoderResult decodeLoop(ByteBuffer @in, CharBuffer @out)
	  {
		while (@in.hasRemaining() && @out.hasRemaining())
		{
		  char ch = (char)(@in.get() & 0xff);
		  if (ch >= 0xA0)
		  {
			ch = TABLE[ch - 0xA0];
		  }
		  @out.put(ch);
		}
		return @in.hasRemaining() ? CoderResult.OVERFLOW : CoderResult.UNDERFLOW;
	  }
Пример #10
0
        internal static Token? TryMatch(CharBuffer cs)
        {
            bool hasPos = cs.TryExpect('+');
            bool hasSign = hasPos || cs.TryExpect('-');

            if (hasSign || cs.TryExpectInRange('0', '9'))
            {
                StringBuilder sb = new StringBuilder(16);
                sb.Append(cs.Consume());

                if (hasSign && !cs.TryExpectInRange('0', '9'))
                {
                    throw Parser.CreateParseError(
                        cs.FilePosition, $"Failed to read Integer. Expected a number but '{cs.Peek().ToReadable()}' was found instead.");
                }

                while (!cs.End && (cs.TryExpectInRange('0', '9') || cs.TryExpect('_')))
                {
                    sb.Append(cs.Consume());
                }

                if (cs.TryExpect('-') && sb.Length == 4 && !hasSign)
                {
                    return DateTimeMatcher.TryMatch(sb, cs);
                }
                else if (((cs.TryExpect('.') && cs.TryExpectAt(3, ':')) || cs.TryExpect(":")) && !hasPos)
                {
                    return TimespanMatcher.ContinueMatchFromInteger(sb, cs);
                }

                if (cs.End || cs.TryExpectWhitespace() || cs.TokenDone())
                {
                    return new Token(TokenType.Integer, sb.ToString());
                }
                else
                {
                    if (cs.TryExpect('E') || cs.TryExpect('e') || cs.TryExpect('.'))
                    {
                        return FloatMatcher.Match(sb, cs);
                    }
                    else
                    {
                        return BareKeyMatcher.TryContinueMatch(sb, cs);
                    }
                }
            }
            else
            {
                return null;
            }
        }
Пример #11
0
        private static void SerializeAddress(CharBuffer b, Marlee.Jsv.Console.Program.Address a)
        {
            b.Write('{');
              if (a.Street != null)
              {
            b.Write("Street:");
            WriteString(b, a.Street);
            b.Write(',');
              }

              b.Write("ID:");
              b.Write(a.ID);
              b.Write('}');
        }
Пример #12
0
        internal static void SerializeCustomerBytes(Marlee.Jsv.Console.Program.Customer c, Stream s)
        {
            //var byteBuffer = new ByteBuffer(256);
              //byteBuffer.WriteInt32(4);
              //byteBuffer.WriteChar('{');
              //byteBuffer.WriteString("test");
              //var s = byteBuffer.ToString();

              var byteBuffer = new CharBuffer(256);

              SerializeCustomer(byteBuffer, c);

              byteBuffer.WriteToStream(s);
              //var x = byteBuffer.ToString();
        }
Пример #13
0
        private static Token? TryMatchInternal(StringBuilder alreadyMatched, CharBuffer cs)
        {
            var sb = alreadyMatched ?? new StringBuilder(64);

            while (!cs.End && cs.Peek().IsBareKeyChar())
            {
                sb.Append(cs.Consume());
            }

            if (sb.Length > 0 && !TokenDone(cs))
            {
                return Token.CreateUnknownTokenFromFragment(cs, sb);
            }

            return sb.Length > 0 ? new Token(TokenType.BareKey, sb.ToString()) : default(Token?);
        }
Пример #14
0
 public static Token? TryMatch(CharBuffer cs)
 {
     if (cs.TryExpect(T))
     {
         cs.Consume(T.Length);
         return new Token(TokenType.Bool, T);
     }
     else if (cs.TryExpect(F))
     {
         cs.Consume(F.Length);
         return new Token(TokenType.Bool, F);
     }
     else
     {
         return null;
     }
 }
Пример #15
0
        internal static Token? Match(StringBuilder beforeFraction, CharBuffer cs)
        {
            if (cs.TryExpect('.'))
            {
                beforeFraction.Append(cs.Consume());
                var errPos = cs.FilePosition;
                var intFrac = IntMatcher.TryMatch(cs);

                if (!intFrac.HasValue)
                {
                    throw Parser.CreateParseError(errPos, "Fraction of float is missing.");
                }
                else if (intFrac.Value.type != TokenType.Integer && intFrac.Value.type != TokenType.Float)
                {
                    throw Parser.CreateParseError(errPos, $"Failed to read float because fraction '{intFrac.Value.value}' is invalid.");
                }

                beforeFraction.Append(intFrac.Value.value);
            }

            if (cs.TryExpect('e') || cs.TryExpect('E'))
            {
                beforeFraction.Append(cs.Consume());
                var errPos = cs.FilePosition;
                var intPar = IntMatcher.TryMatch(cs);
                if (!intPar.HasValue)
                {
                    throw Parser.CreateParseError(errPos, "Exponent of float is missing.");
                }
                else if (intPar.Value.type != TokenType.Integer)
                {
                    throw Parser.CreateParseError(errPos, $"Failed to read float because exponent '{intPar.Value.value}' is invalid.");
                }

                beforeFraction.Append(intPar.Value.value);
            }

            if (cs.TokenDone())
            {
                return new Token(TokenType.Float, beforeFraction.ToString());
            }
            else
            {
                throw Parser.CreateParseError(cs.FilePosition, "Failed to construct float token");
            }
        }
Пример #16
0
        public IEnumerable<StyledToken> Parse(string source)
        {
            var buffer = new CharBuffer(source);

            while (buffer.MoveNext())
            {
                var c = buffer.GetCurrent();

                if (c == HS && buffer.GetNext() == MM)
                {
                    var ec = CheckStyle(buffer);

                    if (ec != NIL)
                    {
                        var sp = buffer.Offset;

                        for (;;)
                        {
                            if (!buffer.MoveNext())
                                break;

                            c = buffer.GetCurrent();

                            if (c == HS && IsEndStyle(buffer, ec))
                            {
                                var ts = ec == S1 ? TextStyle.MultilineStyle1 :
                                    ec == S2 ? TextStyle.MultilineStyle2 :
                                    ec == S3 ? TextStyle.MultilineStyle3 :
                                    ec == S4 ? TextStyle.MultilineStyle4 :
                                    TextStyle.Default;

                                yield return new StyledToken(sp, 5, TextStyle.Invisible);
                                yield return new StyledToken(buffer.Offset, 6, TextStyle.Invisible);
                                yield return new StyledToken(sp + 5, buffer.Offset - sp - 5, ts);

                                break;
                            }
                        }
                    }
                }
            }
        }
Пример #17
0
        internal static Token? ContinueMatchFromInteger(StringBuilder matchedAlready, CharBuffer cs)
        {
            var sb = matchedAlready;

            if (cs.TryExpect("."))
            {
                sb.Append(cs.Consume());
                sb.Append(cs.ExpectAndConsumeDigit());
                sb.Append(cs.ExpectAndConsumeDigit());
            }

            ExpectColonSperatedSegment(sb, cs);

            if (!cs.TokenDone())
            {
                ExpectColonSperatedSegment(sb, cs);
            }

            if (!cs.TokenDone() && cs.TryExpect('.'))
            {
                sb.Append(cs.Consume());
                while (!cs.End && cs.TryExpectDigit())
                {
                    sb.Append(cs.Consume());
                }
            }

            if (cs.TokenDone())
            {
                return new Token(TokenType.Timespan, sb.ToString());
            }
            else
            {
                throw Parser.CreateParseError(cs.FilePosition, $"Failed to parse timespan token because unexpected character '{cs.Peek().ToReadable()}' was found.");
            }
        }
Пример #18
0
        //throws FuseException
        public int readlink(String path, CharBuffer link)
        {
            link.put(fs2.readlink(path));

            return 0;
        }
Пример #19
0
        public IEnumerable <StyledToken> Parse(string source)
        {
            var buffer   = new CharBuffer(source);
            var spacePos = 0;

            while (buffer.MoveNext())
            {
                var c = buffer.GetCurrent();

                if (c == SL && Hyperlinks)
                {
                    if (buffer.GetNext() == SL && buffer.GetPrevious() == DD && spacePos > -1)
                    {
                        var sp  = spacePos > 0 ? spacePos + 1 : spacePos;
                        var ep  = buffer.Offset - 2;
                        var str = buffer.GetString(sp, ep - sp + 1);

                        while (!IsEmptyOrBrace(buffer.GetNext()))
                        {
                            buffer.MoveNext();
                        }

                        yield return(new StyledToken(sp, buffer.Offset - sp + 1, TextStyle.Hyperlink));

                        spacePos = buffer.Offset;
                    }
                }
                else if (c == BS && Bold && IsStart(buffer))
                {
                    var a = buffer.SetAnchor();

                    while (!IsEmpty(buffer.GetNext()))
                    {
                        buffer.MoveNext();
                    }

                    if (buffer.GetCurrent() != BS)
                    {
                        buffer.BackToAnchor();
                    }
                    else
                    {
                        yield return(new StyledToken(a, buffer.Offset - a + 1, TextStyle.Style1));
                    }
                }
                else if (c == IS && Italic && IsStart(buffer))
                {
                    var a = buffer.SetAnchor();

                    while (!IsEmpty(buffer.GetNext()))
                    {
                        buffer.MoveNext();
                    }

                    if (buffer.GetCurrent() != IS)
                    {
                        buffer.BackToAnchor();
                    }
                    else
                    {
                        yield return(new StyledToken(a, buffer.Offset - a + 1, TextStyle.Style2));
                    }
                }
                else if (IsSep(c))
                {
                    spacePos = buffer.Offset;
                }
            }
        }
 /**
  * Decodes bytes into characters. This method is called by the
  * {@link #decode(ByteBuffer, CharBuffer, boolean) decode} method.
  * <p>
  * This method will implement the essential decoding operation, and it won't
  * stop decoding until either all the input bytes are read, the output
  * buffer is filled, or some exception is encountered. Then it will return a
  * <code>CoderResult</code> object indicating the result of current
  * decoding operation. The rules to construct the <code>CoderResult</code>
  * are the same as for
  * {@link #decode(ByteBuffer, CharBuffer, boolean) decode}. When an
  * exception is encountered in the decoding operation, most implementations
  * of this method will return a relevant result object to the
  * {@link #decode(ByteBuffer, CharBuffer, boolean) decode} method, and some
  * performance optimized implementation may handle the exception and
  * implement the error action itself.
  * <p>
  * The buffers are scanned from their current positions, and their positions
  * will be modified accordingly, while their marks and limits will be
  * intact. At most {@link ByteBuffer#remaining() in.remaining()} characters
  * will be read, and {@link CharBuffer#remaining() out.remaining()} bytes
  * will be written.
  * <p>
  * Note that some implementations may pre-scan the input buffer and return a
  * <code>CoderResult.UNDERFLOW</code> until it receives sufficient input.
  *
  * @param in
  *            the input buffer.
  * @param out
  *            the output buffer.
  * @return a <code>CoderResult</code> instance indicating the result.
  */
 protected abstract CoderResult decodeLoop(ByteBuffer inJ, CharBuffer outJ);
        /**
         * Decodes bytes starting at the current position of the given input buffer,
         * and writes the equivalent character sequence into the given output buffer
         * from its current position.
         * <p>
         * The buffers' position will be changed with the reading and writing
         * operation, but their limits and marks will be kept intact.
         * <p>
         * A <code>CoderResult</code> instance will be returned according to
         * following rules:
         * <ul>
         * <li>{@link CoderResult#OVERFLOW CoderResult.OVERFLOW} indicates that
         * even though not all of the input has been processed, the buffer the
         * output is being written to has reached its capacity. In the event of this
         * code being returned this method should be called once more with an
         * <code>out</code> argument that has not already been filled.</li>
         * <li>{@link CoderResult#UNDERFLOW CoderResult.UNDERFLOW} indicates that
         * as many bytes as possible in the input buffer have been decoded. If there
         * is no further input and no remaining bytes in the input buffer then this
         * operation may be regarded as complete. Otherwise, this method should be
         * called once more with additional input.</li>
         * <li>A {@link CoderResult#malformedForLength(int) malformed input} result
         * indicates that some malformed input error has been encountered, and the
         * erroneous bytes start at the input buffer's position and their number can
         * be got by result's {@link CoderResult#length() length}. This kind of
         * result can be returned only if the malformed action is
         * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. </li>
         * <li>A {@link CoderResult#unmappableForLength(int) unmappable character}
         * result indicates that some unmappable character error has been
         * encountered, and the erroneous bytes start at the input buffer's position
         * and their number can be got by result's
         * {@link CoderResult#length() length}. This kind of result can be returned
         * only if the unmappable character action is
         * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. </li>
         * </ul>
         * <p>
         * The <code>endOfInput</code> parameter indicates that the invoker cannot
         * provide further input. This parameter is true if and only if the bytes in
         * current input buffer are all inputs for this decoding operation. Note
         * that it is common and won't cause an error if the invoker sets false and
         * then can't provide more input, while it may cause an error if the invoker
         * always sets true in several consecutive invocations. This would make the
         * remaining input to be treated as malformed input.
         * <p>
         * This method invokes the
         * {@link #decodeLoop(ByteBuffer, CharBuffer) decodeLoop} method to
         * implement the basic decode logic for a specific charset.
         *
         * @param in
         *            the input buffer.
         * @param out
         *            the output buffer.
         * @param endOfInput
         *            true if all the input characters have been provided.
         * @return a <code>CoderResult</code> instance which indicates the reason
         *         of termination.
         * @throws IllegalStateException
         *             if decoding has started or no more input is needed in this
         *             decoding progress.
         * @throws CoderMalfunctionError
         *             if the {@link #decodeLoop(ByteBuffer, CharBuffer) decodeLoop}
         *             method threw an <code>BufferUnderflowException</code> or
         *             <code>BufferOverflowException</code>.
         */
        public CoderResult decode(ByteBuffer inJ, CharBuffer outJ,
                bool endOfInput)
        {
            /*
             * status check
             */
            if ((status == FLUSH) || (!endOfInput && status == END)) {
                throw new java.lang.IllegalStateException();
            }

            CoderResult result = null;

            // begin to decode
            while (true) {
                CodingErrorAction action = null;
                try {
                    result = decodeLoop(inJ, outJ);
                } catch (BufferOverflowException ex) {
                    // unexpected exception
                    throw new CoderMalfunctionError(ex);
                } catch (BufferUnderflowException ex) {
                    // unexpected exception
                    throw new CoderMalfunctionError(ex);
                }

                /*
                 * result handling
                 */
                if (result.isUnderflow()) {
                    int remaining = inJ.remaining(); // WHY inJ.remaining() == 1?
                    status = endOfInput ? END : ONGOING;
                    if (endOfInput && remaining > 0) {
                        result = CoderResult.malformedForLength(remaining);
                    } else {
                        return result;
                    }
                }
                if (result.isOverflow()) {
                    return result;
                }
                // set coding error handle action
                action = malformAction;
                if (result.isUnmappable()) {
                    action = unmapAction;
                }
                // If the action is IGNORE or REPLACE, we should continue decoding.
                if (action == CodingErrorAction.REPLACE) {
                    if (outJ.remaining() < replace.length()) {
                        return CoderResult.OVERFLOW;
                    }
                    outJ.put(replace);
                } else {
                    if (action != CodingErrorAction.IGNORE)
                        return result;
                }
                inJ.position(inJ.position() + result.length());
            }
        }
Пример #22
0
 // implementation of canEncode
 private bool implCanEncode(CharBuffer cb)
 {
     if (status == FLUSH || status == INIT) {
         status = READY;
     }
     if (status != READY) {
         // niochar.0B=Another encoding process is ongoing\!
         throw new java.lang.IllegalStateException("Another encoding process is ongoing!"); //$NON-NLS-1$
     }
     CodingErrorAction malformBak = malformAction;
     CodingErrorAction unmapBak = unmapAction;
     onMalformedInput(CodingErrorAction.REPORT);
     onUnmappableCharacter(CodingErrorAction.REPORT);
     bool result = true;
     try {
         this.encode(cb);
     } catch (CharacterCodingException e) {
         result = false;
     }
     onMalformedInput(malformBak);
     onUnmappableCharacter(unmapBak);
     reset();
     return result;
 }
Пример #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Lexer"/> class.
 /// </summary>
 /// <param name="value">The value.</param>
 protected Lexer(string value)
 {
     _buffer = new CharBuffer(value);
     _states = new Stack<int>();
 }
Пример #24
0
 public override int read(CharBuffer target)
 {
     throw new System.NotSupportedException("read(CharBuffer)");
 }
Пример #25
0
 public ByteBuffer encode(CharBuffer prm1)
 {
     return(default(ByteBuffer));
 }
Пример #26
0
 public CoderResult encode(CharBuffer prm1, ByteBuffer prm2, bool prm3)
 {
     return(default(CoderResult));
 }
Пример #27
0
 protected virtual CoderResult encodeLoop(CharBuffer prm1, ByteBuffer prm2)
 {
     return(default(CoderResult));
 }
Пример #28
0
 /// <summary>
 /// Read a chiral configuration from a character buffer and progress the
 /// buffer. If there is no configuration then <see cref="Unknown"/>
 /// is returned. Encountering an invalid permutation designator (e.g.
 /// &#64;TB21) or incomplete class (e.g. &#64;T) will throw an invalid smiles
 /// exception.
 /// </summary>
 /// <param name="buffer">a character buffer</param>
 /// <returns>the configuration</returns>
 internal static Configuration Read(CharBuffer buffer)
 {
     if (buffer.GetIf('@'))
     {
         if (buffer.GetIf('@'))
         {
             return(Configuration.Clockwise);
         }
         else if (buffer.GetIf('1'))
         {
             return(Configuration.AntiClockwise);
         }
         else if (buffer.GetIf('2'))
         {
             return(Configuration.Clockwise);
         }
         else if (buffer.GetIf('T'))
         {
             // TH (tetrahedral) or TB (trigonal bipyramidal)
             if (buffer.GetIf('H'))
             {
                 if (buffer.GetIf('1'))
                 {
                     return(Configuration.TH1);
                 }
                 else if (buffer.GetIf('2'))
                 {
                     return(Configuration.TH2);
                 }
                 else
                 {
                     throw new InvalidSmilesException("invalid permutation designator for @TH, valid values are @TH1 or @TH2:",
                                                      buffer);
                 }
             }
             else if (buffer.GetIf('B'))
             {
                 int num = buffer.GetNumber();
                 if (num < 1 || num > 20)
                 {
                     throw new InvalidSmilesException("invalid permutation designator for @TB, valid values are '@TB1, @TB2, ... @TB20:'",
                                                      buffer);
                 }
                 return(tbs[num]);
             }
             throw new InvalidSmilesException("'@T' is not a valid chiral specification:", buffer);
         }
         else if (buffer.GetIf('D'))
         {
             // DB (double bond)
             if (buffer.GetIf('B'))
             {
                 if (buffer.GetIf('1'))
                 {
                     return(Configuration.DB1);
                 }
                 else if (buffer.GetIf('2'))
                 {
                     return(Configuration.DB2);
                 }
                 else
                 {
                     throw new InvalidSmilesException("invalid permutation designator for @DB, valid values are @DB1 or @DB2:",
                                                      buffer);
                 }
             }
             throw new InvalidSmilesException("'@D' is not a valid chiral specification:", buffer);
         }
         else if (buffer.GetIf('A'))
         {
             // allene (extended tetrahedral)
             if (buffer.GetIf('L'))
             {
                 if (buffer.GetIf('1'))
                 {
                     return(Configuration.AL1);
                 }
                 else if (buffer.GetIf('2'))
                 {
                     return(Configuration.AL2);
                 }
                 else
                 {
                     throw new InvalidSmilesException("invalid permutation designator for @AL, valid values are '@AL1 or @AL2':", buffer);
                 }
             }
             else
             {
                 throw new InvalidSmilesException("'@A' is not a valid chiral specification:", buffer);
             }
         }
         else if (buffer.GetIf('S'))
         {
             // square planar
             if (buffer.GetIf('P'))
             {
                 if (buffer.GetIf('1'))
                 {
                     return(Configuration.SP1);
                 }
                 else if (buffer.GetIf('2'))
                 {
                     return(Configuration.SP2);
                 }
                 else if (buffer.GetIf('3'))
                 {
                     return(Configuration.SP3);
                 }
                 else
                 {
                     throw new InvalidSmilesException("invalid permutation designator for @SP, valid values are '@SP1, @SP2 or @SP3':",
                                                      buffer);
                 }
             }
             else
             {
                 throw new InvalidSmilesException("'@S' is not a valid chiral specification:", buffer);
             }
         }
         else if (buffer.GetIf('O'))
         {
             if (buffer.GetIf('H'))
             {
                 // octahedral
                 int num = buffer.GetNumber();
                 if (num < 1 || num > 30)
                 {
                     throw new InvalidSmilesException("invalid permutation designator for @OH, valud values are '@OH1, @OH2, ... @OH30':", buffer);
                 }
                 return(ohs[num]);
             }
             else
             {
                 throw new InvalidSmilesException("'@O' is not a valid chiral specification:", buffer);
             }
         }
         else
         {
             return(Configuration.AntiClockwise);
         }
     }
     return(Unknown);
 }
Пример #29
0
 public override CharBuffer put(CharBuffer src)
 {
     throw new ReadOnlyBufferException();
 }
Пример #30
0
        internal static Token? TryMatch(StringBuilder matchedAlready, CharBuffer cs)
        {
            var sb = matchedAlready;
            Debug.Assert(cs.TryExpect('-'));

            sb.Append(cs.Consume());

            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpect('-')) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpect('T')) { sb.Append(cs.Consume()); } else { return FinishDatetimeToken(sb); }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpect(':')) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpect(':')) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
            if (cs.TryExpect('Z'))
            {
                sb.Append(cs.Consume());
                if (cs.TokenDone())
                {
                    return FinishDatetimeToken(sb);
                }
                else
                {
                    return null;
                }
            }
            else if (cs.TryExpect('-') || cs.TryExpect('+'))
            {
                sb.Append(cs.Consume());

                if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
                if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
                if (cs.TryExpect(':')) { sb.Append(cs.Consume()); } else { return null; }
                if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
                if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }

                if (cs.TokenDone())
                {
                    return FinishDatetimeToken(sb);
                }
                else
                {
                    return null;
                }
            }
            else if (cs.TryExpect('.'))
            {
                sb.Append(cs.Consume());

                while (cs.TryExpectDigit())
                {
                    sb.Append(cs.Consume());
                }

                if (cs.TryExpect('-') || cs.TryExpect('+')) { sb.Append(cs.Consume()); } else { return FinishDatetimeToken(sb); }
                if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
                if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
                if (cs.TryExpect(':')) { sb.Append(cs.Consume()); } else { return null; }
                if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }
                if (cs.TryExpectDigit()) { sb.Append(cs.Consume()); } else { return null; }

                if (cs.TokenDone())
                {
                    return FinishDatetimeToken(sb);
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return FinishDatetimeToken(sb);
            }
        }
Пример #31
0
        private IntPtr ProcOnNotify(IntPtr hwnd, IntPtr lParam)
        {
            IntPtr   hres      = IntPtr.Zero;
            OFNOTIFY structure = (OFNOTIFY)Marshal.PtrToStructure(lParam, typeof(OFNOTIFY));

            switch ((NativeMethods.DialogChangeStatus)structure.hdr_code)
            {
            case NativeMethods.DialogChangeStatus.CDN_FILEOK:    //- 606:
                if (this._ignoreSecondFileOkNotification)
                {
                    if (this._fileOkNotificationCount != 0)
                    {
                        this._ignoreSecondFileOkNotification = false;
                        NativeMethods.CriticalSetWindowLong(new HandleRef(this, hwnd), 0, InvalidIntPtr);
                        hres = InvalidIntPtr;
                        break;
                    }
                    this._fileOkNotificationCount = 1;
                }

                if (!this.DoFileOk(structure.lpOFN))
                {
                    NativeMethods.CriticalSetWindowLong(new HandleRef(this, hwnd), 0, InvalidIntPtr);
                    hres = InvalidIntPtr;
                }
                break;

            case NativeMethods.DialogChangeStatus.CDN_TYPECHANGE:
            {
                OPENFILENAME_I ofn = (OPENFILENAME_I)Marshal.PtrToStructure(structure.lpOFN, typeof(OPENFILENAME_I));
                int            i   = ofn.nFilterIndex;

                OnFilterChanged(this, i);
            }
            break;

            case NativeMethods.DialogChangeStatus.CDN_HELP:    // - 605:
                break;

            case NativeMethods.DialogChangeStatus.CDN_FOLDERCHANGE:    //- 603:
            {
                StringBuilder folderPath = new StringBuilder(256);
                NativeMethods.SendMessage(new HandleRef(this, structure.hdr_hwndFrom), (int)DialogChangeProperties.CDM_GETFOLDERPATH, (IntPtr)256, folderPath);
                OnPathChanged(this, folderPath.ToString());
                folderPath.Length = 0;
            }
            break;

            case NativeMethods.DialogChangeStatus.CDN_SHAREVIOLATION:    //- 604:
                this._ignoreSecondFileOkNotification = true;
                this._fileOkNotificationCount        = 0;
                break;

            case NativeMethods.DialogChangeStatus.CDN_SELCHANGE:    //- 602:
            {
                OPENFILENAME_I openfilename_i = (OPENFILENAME_I)Marshal.PtrToStructure(structure.lpOFN, typeof(OPENFILENAME_I));
                int            num            = (int)NativeMethods.UnsafeSendMessage(this._hwndFileDialog, 0x464, IntPtr.Zero, IntPtr.Zero);
                if (num > openfilename_i.nMaxFile)
                {
                    int        size   = num + 0x800;
                    CharBuffer buffer = CharBuffer.CreateBuffer(size);
                    IntPtr     ptr2   = buffer.AllocCoTaskMem();
                    Marshal.FreeCoTaskMem(openfilename_i.lpstrFile);
                    openfilename_i.lpstrFile = ptr2;
                    openfilename_i.nMaxFile  = size;
                    this._charBuffer         = buffer;
                    Marshal.StructureToPtr(openfilename_i, structure.lpOFN, true);
                    Marshal.StructureToPtr(structure, lParam, true);
                }
                StringBuilder filePath = new StringBuilder(256);
                NativeMethods.SendMessage(new HandleRef(this, structure.hdr_hwndFrom), (uint)DialogChangeProperties.CDM_GETFILEPATH, (IntPtr)256, filePath);
                OnPathChanged(this, filePath.ToString());
                filePath.Length = 0;
                break;
            }

            case NativeMethods.DialogChangeStatus.CDN_INITDONE:    //- 601:
            {
                NativeMethods.PostMessage(new HandleRef(this, this._hwndFileDialogEmbedded), MSG_POST_CREATION, IntPtr.Zero, IntPtr.Zero);
            }
            break;
            }
            return(hres);
        }
Пример #32
0
        //throws CharacterCodingException
        /**
         * This is a facade method for the encoding operation.
         * <p>
         * This method encodes the remaining character sequence of the given
         * character buffer into a new byte buffer. This method performs a complete
         * encoding operation, resets at first, then encodes, and flushes at last.
         * <p>
         * This method should not be invoked if another encode operation is ongoing.
         *
         * @param in
         *            the input buffer.
         * @return a new <code>ByteBuffer</code> containing the bytes produced by
         *         this encoding operation. The buffer's limit will be the position
         *         of the last byte in the buffer, and the position will be zero.
         * @throws IllegalStateException
         *             if another encoding operation is ongoing.
         * @throws MalformedInputException
         *             if an illegal input character sequence for this charset is
         *             encountered, and the action for malformed error is
         *             {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}
         * @throws UnmappableCharacterException
         *             if a legal but unmappable input character sequence for this
         *             charset is encountered, and the action for unmappable
         *             character error is
         *             {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}.
         *             Unmappable means the Unicode character sequence at the input
         *             buffer's current position cannot be mapped to a equivalent
         *             byte sequence.
         * @throws CharacterCodingException
         *             if other exception happened during the encode operation.
         */
        public ByteBuffer encode(CharBuffer inJ)
        {
            if (inJ.remaining() == 0) {
                return ByteBuffer.allocate(0);
            }
            reset();
            int length = (int) (inJ.remaining() * averBytes);
            ByteBuffer output = ByteBuffer.allocate(length);
            CoderResult result = null;
            while (true) {
                result = encode(inJ, output, false);
                if (result==CoderResult.UNDERFLOW) {
                    break;
                } else if (result==CoderResult.OVERFLOW) {
                    output = allocateMore(output);
                    continue;
                }
                checkCoderResult(result);
            }
            result = encode(inJ, output, true);
            checkCoderResult(result);

            while (true) {
                result = flush(output);
                if (result==CoderResult.UNDERFLOW) {
                    output.flip();
                    break;
                } else if (result==CoderResult.OVERFLOW) {
                    output = allocateMore(output);
                    continue;
                }
                checkCoderResult(result);
                output.flip();
                if (result.isMalformed()) {
                    throw new MalformedInputException(result.length());
                } else if (result.isUnmappable()) {
                    throw new UnmappableCharacterException(result.length());
                }
                break;
            }
            status = READY;
            finished = true;
            return output;
        }
Пример #33
0
 /// <summary>
 /// Builds a <see cref="CharsTrie"/> for the <see cref="Add(string, int)"/>ed data and char-serializes it.
 /// Once built, no further data can be <see cref="Add(string, int)"/>ed until <see cref="Clear()"/> is called.
 /// </summary>
 /// <remarks>
 /// A <see cref="CharsTrie"/> cannot be empty. At least one (string, value) pair
 /// must have been <see cref="Add(string, int)"/>ed.
 /// <para/>
 /// Multiple calls to <see cref="Build(Option)"/> or <see cref="BuildCharSequence(Option)"/> return tries or sequences
 /// which share the builder's char array, without rebuilding.
 /// After <see cref="Clear()"/> has been called, a new array will be used.
 /// </remarks>
 /// <param name="buildOption">Build option, see <see cref="StringTrieBuilder.Option"/>.</param>
 /// <returns>A <see cref="ICharSequence"/> with the char-serialized <see cref="CharsTrie"/> for the <see cref="Add(string, int)"/>ed data.</returns>
 /// <stable>ICU 4.8</stable>
 public ICharSequence BuildCharSequence(StringTrieBuilder.Option buildOption)
 {
     BuildChars(buildOption);
     return(CharBuffer.Wrap(chars, chars.Length - charsLength, charsLength));
 }
Пример #34
0
 private static void ExpectColonSperatedSegment(StringBuilder sb, CharBuffer cs)
 {
     sb.Append(cs.ExpectAndConsume(':'));
     sb.Append(cs.ExpectAndConsumeDigit());
     sb.Append(cs.ExpectAndConsumeDigit());
 }
        /// <summary>
        /// Searches the automaton for a symbol sequence equal to <paramref name="word"/>,
        /// followed by a separator. The result is a stem (decompressed accordingly
        /// to the dictionary's specification) and an optional tag data.
        /// </summary>
        public IList <WordData> Lookup(string word)
        {
            byte separator = dictionaryMetadata.Separator;

#pragma warning disable 612, 618
            int prefixBytes = sequenceEncoder.PrefixBytes;
#pragma warning restore 612, 618

            if (dictionaryMetadata.InputConversionPairs.Any())
            {
                word = ApplyReplacements(word, dictionaryMetadata.InputConversionPairs);
            }

            // Reset the output list to zero length.
            formsList.Wrap(forms, 0, 0);

            // Encode word characters into bytes in the same encoding as the FSA's.
            charBuffer = BufferUtils.ClearAndEnsureCapacity(charBuffer, word.Length);
            for (int i = 0; i < word.Length; i++)
            {
                char chr = word[i];
                if (chr == separatorChar)
                {
                    // No valid input can contain the separator.
                    return(formsList);
                }
                charBuffer.Put(chr);
            }
            charBuffer.Flip();
            try
            {
                byteBuffer = BufferUtils.CharsToBytes(encoder, charBuffer, byteBuffer);
            }
            catch (UnmappableInputException)
            {
                // This should be a rare occurrence, but if it happens it means there is no way
                // the dictionary can contain the input word.
                return(formsList);
            }

            // Try to find a partial match in the dictionary.
            MatchResult match = matcher.Match(matchResult, byteBuffer
                                              .Array, 0, byteBuffer.Remaining, rootNode);

            if (match.Kind == MatchResult.SequenceIsAPrefix)
            {
                /*
                 * The entire sequence exists in the dictionary. A separator should
                 * be the next symbol.
                 */
                int arc = fsa.GetArc(match.Node, separator);

                /*
                 * The situation when the arc points to a final node should NEVER
                 * happen. After all, we want the word to have SOME base form.
                 */
                if (arc != 0 && !fsa.IsArcFinal(arc))
                {
                    // There is such a word in the dictionary. Return its base forms.
                    int formsCount = 0;

                    finalStatesIterator.RestartFrom(fsa.GetEndNode(arc));
                    while (finalStatesIterator.MoveNext())
                    {
                        ByteBuffer bb     = finalStatesIterator.Current;
                        byte[]     ba     = bb.Array;
                        int        bbSize = bb.Remaining;

                        if (formsCount >= forms.Length)
                        {
                            //forms = Arrays.CopyOf(forms, forms.Length + EXPAND_SIZE);
                            Array.Resize(ref forms, forms.Length + ExpandSize);
                            for (int k = 0; k < forms.Length; k++)
                            {
                                if (forms[k] == null)
                                {
                                    forms[k] = new WordData(decoder);
                                }
                            }
                        }

                        /*
                         * Now, expand the prefix/ suffix 'compression' and store
                         * the base form.
                         */
                        WordData wordData = forms[formsCount++];
                        if (!dictionaryMetadata.OutputConversionPairs.Any())
                        {
                            wordData.Update(byteBuffer, word);
                        }
                        else
                        {
                            wordData.Update(byteBuffer, ApplyReplacements(word, dictionaryMetadata.OutputConversionPairs));
                        }

                        /*
                         * Find the separator byte's position splitting the inflection instructions
                         * from the tag.
                         */
                        Debug.Assert(prefixBytes <= bbSize, sequenceEncoder.GetType() + " >? " + bbSize);
                        int sepPos;
                        for (sepPos = prefixBytes; sepPos < bbSize; sepPos++)
                        {
                            if (ba[sepPos] == separator)
                            {
                                break;
                            }
                        }

                        /*
                         * Decode the stem into stem buffer.
                         */
                        wordData.stemBuffer = sequenceEncoder.Decode(wordData.stemBuffer,
                                                                     byteBuffer,
                                                                     ByteBuffer.Wrap(ba, 0, sepPos));

                        // Skip separator character.
                        sepPos++;

                        /*
                         * Decode the tag data.
                         */
                        int tagSize = bbSize - sepPos;
                        if (tagSize > 0)
                        {
                            wordData.tagBuffer = BufferUtils.ClearAndEnsureCapacity(wordData.tagBuffer, tagSize);
                            wordData.tagBuffer.Put(ba, sepPos, tagSize);
                            wordData.tagBuffer.Flip();
                        }
                    }

                    formsList.Wrap(forms, 0, formsCount);
                }
            }
            else
            {
                /*
                 * this case is somewhat confusing: we should have hit the separator
                 * first... I don't really know how to deal with it at the time
                 * being.
                 */
            }
            return(formsList);
        }
Пример #36
0
        //throws FuseException
        public int readlink(String path, CharBuffer link)
        {
            N n = lookup(path);

            if (n is L)
            {
                link.append(new StringJ(((L)n).link));
                return 0;
            }

            return Errno.ENOENT;
        }
Пример #37
0
 protected virtual CoderResult implFlush(CharBuffer prm1)
 {
     return(default(CoderResult));
 }
 /**
  * Flushes this decoder.
  *
  * This method will call {@link #implFlush(CharBuffer) implFlush}. Some
  * decoders may need to write some characters to the output buffer when they
  * have read all input bytes; subclasses can override
  * {@link #implFlush(CharBuffer) implFlush} to perform the writing operation.
  * <p>
  * The maximum number of written bytes won't be larger than
  * {@link CharBuffer#remaining() out.remaining()}. If some decoder wants to
  * write more bytes than an output buffer's remaining space allows, then a
  * <code>CoderResult.OVERFLOW</code> will be returned, and this method
  * must be called again with a character buffer that has more remaining
  * space. Otherwise this method will return
  * <code>CoderResult.UNDERFLOW</code>, which means one decoding process
  * has been completed successfully.
  * <p>
  * During the flush, the output buffer's position will be changed
  * accordingly, while its mark and limit will be intact.
  *
  * @param out
  *            the given output buffer.
  * @return <code>CoderResult.UNDERFLOW</code> or
  *         <code>CoderResult.OVERFLOW</code>.
  * @throws IllegalStateException
  *             if this decoder hasn't read all input bytes during one
  *             decoding process, which means neither after calling
  *             {@link #decode(ByteBuffer) decode(ByteBuffer)} nor after
  *             calling {@link #decode(ByteBuffer, CharBuffer, boolean)
  *             decode(ByteBuffer, CharBuffer, boolean)} with true as value
  *             for the last boolean parameter.
  */
 public CoderResult flush(CharBuffer outJ)
 {
     if (status != END && status != INIT) {
         throw new java.lang.IllegalStateException();
     }
     CoderResult result = implFlush(outJ);
     if (result == CoderResult.UNDERFLOW) {
         status = FLUSH;
     }
     return result;
 }
Пример #39
0
 public CoderResult flush(CharBuffer prm1)
 {
     return(default(CoderResult));
 }
 /**
  * Flushes this decoder. The default implementation does nothing and always
  * returns <code>CoderResult.UNDERFLOW</code>; this method can be
  * overridden if needed.
  *
  * @param out
  *            the output buffer.
  * @return <code>CoderResult.UNDERFLOW</code> or
  *         <code>CoderResult.OVERFLOW</code>.
  */
 protected CoderResult implFlush(CharBuffer outJ)
 {
     return CoderResult.UNDERFLOW;
 }
Пример #41
0
        /// <summary>
        /// Encodes as many characters as possible from the given input buffer,
        /// writing the results to the given output buffer.
        ///
        /// <para> The buffers are read from, and written to, starting at their current
        /// positions.  At most <seealso cref="Buffer#remaining in.remaining()"/> characters
        /// will be read and at most <seealso cref="Buffer#remaining out.remaining()"/>
        /// bytes will be written.  The buffers' positions will be advanced to
        /// reflect the characters read and the bytes written, but their marks and
        /// limits will not be modified.
        ///
        /// </para>
        /// <para> In addition to reading characters from the input buffer and writing
        /// bytes to the output buffer, this method returns a <seealso cref="CoderResult"/>
        /// object to describe its reason for termination:
        ///
        /// <ul>
        ///
        /// </para>
        ///   <li><para> <seealso cref="CoderResult#UNDERFLOW"/> indicates that as much of the
        ///   input buffer as possible has been encoded.  If there is no further
        ///   input then the invoker can proceed to the next step of the
        ///   <a href="#steps">encoding operation</a>.  Otherwise this method
        ///   should be invoked again with further input.  </para></li>
        ///
        ///   <li><para> <seealso cref="CoderResult#OVERFLOW"/> indicates that there is
        ///   insufficient space in the output buffer to encode any more characters.
        ///   This method should be invoked again with an output buffer that has
        ///   more <seealso cref="Buffer#remaining remaining"/> bytes. This is
        ///   typically done by draining any encoded bytes from the output
        ///   buffer.  </para></li>
        ///
        ///   <li><para> A {@link CoderResult#malformedForLength
        ///   malformed-input} result indicates that a malformed-input
        ///   error has been detected.  The malformed characters begin at the input
        ///   buffer's (possibly incremented) position; the number of malformed
        ///   characters may be determined by invoking the result object's {@link
        ///   CoderResult#length() length} method.  This case applies only if the
        ///   <seealso cref="#onMalformedInput malformed action"/> of this encoder
        ///   is <seealso cref="CodingErrorAction#REPORT"/>; otherwise the malformed input
        ///   will be ignored or replaced, as requested.  </para></li>
        ///
        ///   <li><para> An {@link CoderResult#unmappableForLength
        ///   unmappable-character} result indicates that an
        ///   unmappable-character error has been detected.  The characters that
        ///   encode the unmappable character begin at the input buffer's (possibly
        ///   incremented) position; the number of such characters may be determined
        ///   by invoking the result object's <seealso cref="CoderResult#length() length"/>
        ///   method.  This case applies only if the {@link #onUnmappableCharacter
        ///   unmappable action} of this encoder is {@link
        ///   CodingErrorAction#REPORT}; otherwise the unmappable character will be
        ///   ignored or replaced, as requested.  </para></li>
        ///
        /// </ul>
        ///
        /// In any case, if this method is to be reinvoked in the same encoding
        /// operation then care should be taken to preserve any characters remaining
        /// in the input buffer so that they are available to the next invocation.
        ///
        /// <para> The <tt>endOfInput</tt> parameter advises this method as to whether
        /// the invoker can provide further input beyond that contained in the given
        /// input buffer.  If there is a possibility of providing additional input
        /// then the invoker should pass <tt>false</tt> for this parameter; if there
        /// is no possibility of providing further input then the invoker should
        /// pass <tt>true</tt>.  It is not erroneous, and in fact it is quite
        /// common, to pass <tt>false</tt> in one invocation and later discover that
        /// no further input was actually available.  It is critical, however, that
        /// the final invocation of this method in a sequence of invocations always
        /// pass <tt>true</tt> so that any remaining unencoded input will be treated
        /// as being malformed.
        ///
        /// </para>
        /// <para> This method works by invoking the <seealso cref="#encodeLoop encodeLoop"/>
        /// method, interpreting its results, handling error conditions, and
        /// reinvoking it as necessary.  </para>
        ///
        /// </summary>
        /// <param name="in">
        ///         The input character buffer
        /// </param>
        /// <param name="out">
        ///         The output byte buffer
        /// </param>
        /// <param name="endOfInput">
        ///         <tt>true</tt> if, and only if, the invoker can provide no
        ///         additional input characters beyond those in the given buffer
        /// </param>
        /// <returns>  A coder-result object describing the reason for termination
        /// </returns>
        /// <exception cref="IllegalStateException">
        ///          If an encoding operation is already in progress and the previous
        ///          step was an invocation neither of the <seealso cref="#reset reset"/>
        ///          method, nor of this method with a value of <tt>false</tt> for
        ///          the <tt>endOfInput</tt> parameter, nor of this method with a
        ///          value of <tt>true</tt> for the <tt>endOfInput</tt> parameter
        ///          but a return value indicating an incomplete encoding operation
        /// </exception>
        /// <exception cref="CoderMalfunctionError">
        ///          If an invocation of the encodeLoop method threw
        ///          an unexpected exception </exception>
        public CoderResult Encode(CharBuffer @in, ByteBuffer @out, bool endOfInput)
        {
            int newState = endOfInput ? ST_END : ST_CODING;

            if ((State != ST_RESET) && (State != ST_CODING) && !(endOfInput && (State == ST_END)))
            {
                ThrowIllegalStateException(State, newState);
            }
            State = newState;

            for (;;)
            {
                CoderResult cr;
                try
                {
                    cr = EncodeLoop(@in, @out);
                }
                catch (BufferUnderflowException x)
                {
                    throw new CoderMalfunctionError(x);
                }
                catch (BufferOverflowException x)
                {
                    throw new CoderMalfunctionError(x);
                }

                if (cr.Overflow)
                {
                    return(cr);
                }

                if (cr.Underflow)
                {
                    if (endOfInput && @in.HasRemaining())
                    {
                        cr = CoderResult.MalformedForLength(@in.Remaining());
                        // Fall through to malformed-input case
                    }
                    else
                    {
                        return(cr);
                    }
                }

                CodingErrorAction action = null;
                if (cr.Malformed)
                {
                    action = MalformedInputAction_Renamed;
                }
                else if (cr.Unmappable)
                {
                    action = UnmappableCharacterAction_Renamed;
                }
                else
                {
                    Debug.Assert(false, cr.ToString());
                }

                if (action == CodingErrorAction.REPORT)
                {
                    return(cr);
                }

                if (action == CodingErrorAction.REPLACE)
                {
                    if (@out.Remaining() < Replacement_Renamed.Length)
                    {
                        return(CoderResult.OVERFLOW);
                    }
                    @out.Put(Replacement_Renamed);
                }

                if ((action == CodingErrorAction.IGNORE) || (action == CodingErrorAction.REPLACE))
                {
                    // Skip erroneous input either way
                    @in.Position(@in.Position() + cr.Length());
                    continue;
                }

                Debug.Assert(false);
            }
        }
Пример #42
0
 public override CharBuffer put(CharBuffer prm1)
 {
     return(default(CharBuffer));
 }
Пример #43
0
 private bool IsEndStyle(CharBuffer buffer, char c)
 {
     return(buffer.Get(1) == SL && buffer.Get(2) == MM && buffer.Get(3) == c &&
            buffer.Get(4) == MM && buffer.Get(5) == HE);
 }