Exemplo n.º 1
0
 public Context(string text)
 {
     mTokenizer = new StringTokenizer(text);
     mTokenizer.IgnoreWhiteSpace = true;
     mTokenizer.SymbolChars = new char[] {':',';'};
     NextToken();
 }
Exemplo n.º 2
0
        public void TestKeywordMatcher()
        {
            KeywordMatcher matcher = new KeywordMatcher("invalid", TokenType.INVALID, Delimiters, false);
            StringTokenizer data = new StringTokenizer("+=+//= invalid=invalidinvalid$=");
            SourcePosition streamPos = new SourcePosition(0, 0, 0);

            // Match a basic delimiter keyword
            Assert.AreEqual(Delimiters.Find(m => m.Keyword == "+=").MatchNext(data, ref streamPos, Log).Type, TokenType.AddAssign);
            Assert.AreEqual(data.CurrentItem, "+");
            data.Advance();
            // Assert that the matched token contains the value
            Assert.AreEqual(Delimiters.Find(m => m.Keyword == "/").MatchNext(data, ref streamPos, Log).Value, "/");
            Assert.AreEqual(data.CurrentItem, "/");
            data.Advance(3);
            // Match against a keyword rather than short operator as well as delimiter
            Assert.IsNotNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "=");
            data.Advance();
            // Assert that non-delimiters will prevent a match
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "i");
            data.Advance(14);
            // Ensure EOF with keywords
            Assert.IsNotNull(Delimiters.Find(m => m.Keyword == "$=").MatchNext(data, ref streamPos, Log));

            Assert.IsTrue(data.AtEnd());
        }
Exemplo n.º 3
0
 public void countTokensTest()
 {
     string str = "two tokens"; // TODO: Initialize to an appropriate value
     StringTokenizer target = new StringTokenizer(str); // TODO: Initialize to an appropriate value
     int expected = 2; // TODO: Initialize to an appropriate value
     int actual;
     actual = target.countTokens();
     Assert.AreEqual(expected, actual);
 }
        /// <summary> It recognizes informal sentences in which an eojeol is quite long and some characters were
        /// repeated many times. To prevent decrease of analysis performance because of those unimportant
        /// irregular pattern, it inserts some blanks in those eojeols to seperate them.
        /// </summary>
        public virtual PlainSentence doProcess(PlainSentence ps)
        {
            System.String word = null;
            System.Text.StringBuilder buf = new System.Text.StringBuilder();
            StringTokenizer st = new StringTokenizer(ps.Sentence, " \t");

            while (st.HasMoreTokens)
            {
                word = st.NextToken;

                /* repeated character */
                if (word.Length > REPEAT_CHAR_ALLOWED)
                {
                    char[] wordArray = word.ToCharArray();
                    int repeatCnt = 0;
                    char checkChar = wordArray[0];

                    buf.Append(checkChar);

                    for (int i = 1; i < wordArray.Length; i++)
                    {
                        if (checkChar == wordArray[i])
                        {
                            if (repeatCnt == REPEAT_CHAR_ALLOWED - 1)
                            {
                                buf.Append(' ');
                                buf.Append(wordArray[i]);
                                repeatCnt = 0;
                            }
                            else
                            {
                                buf.Append(wordArray[i]);
                                repeatCnt++;
                            }
                        }
                        else
                        {
                            if (checkChar == '.')
                            {
                                buf.Append(' ');
                            }
                            buf.Append(wordArray[i]);
                            checkChar = wordArray[i];
                            repeatCnt = 0;
                        }
                    }
                }
                else
                {
                    buf.Append(word);
                }
                buf.Append(' ');
            }
            ps.Sentence = buf.ToString();
            return ps;
        }
        public void ExpectedBehavior()
        {
            var tokenizer = new StringTokenizer
            {
                Operators = new[] {" ", "--", "-"}
            };

            var result = tokenizer.Tokenize("-foo- -foo");
            result.ShouldEqual(new[] {"-", "foo", "-", " ", "-", "foo"});
        }
Exemplo n.º 6
0
 protected int[][] GetOutcomePatterns() {
     var numOCTypes = ReadInt();
     var outcomePatterns = new int[numOCTypes][];
     for (var i = 0; i < numOCTypes; i++) {
         var tok = new StringTokenizer(ReadString(), " ");
         var infoInts = new int[tok.CountTokens];
         for (var j = 0; tok.HasMoreTokens; j++) {
             infoInts[j] = int.Parse(tok.NextToken);
         }
         outcomePatterns[i] = infoInts;
     }
     return outcomePatterns;
 }
Exemplo n.º 7
0
 public void hasMoreTokensTest()
 {
     string str = "1 2 3"; // TODO: Initialize to an appropriate value
     StringTokenizer target = new StringTokenizer(str); // TODO: Initialize to an appropriate value
     int expected = 3; // TODO: Initialize to an appropriate value
     int actual = 0;
     while (target.hasMoreTokens())
     {
         actual++;
         target.nextToken();
     }
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 8
0
        /// <inheritdoc />
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            // Always strip the outer tag name as we never want <environment> to render
            output.TagName = null;

            if (string.IsNullOrWhiteSpace(Names))
            {
                // No names specified, do nothing
                return;
            }

            var currentEnvironmentName = HostingEnvironment.EnvironmentName?.Trim();
            if (string.IsNullOrEmpty(currentEnvironmentName))
            {
                // No current environment name, do nothing
                return;
            }

            var tokenizer = new StringTokenizer(Names, NameSeparator);
            var hasEnvironments = false;
            foreach (var item in tokenizer)
            {
                var environment = item.Trim();
                if (environment.HasValue && environment.Length > 0)
                {
                    hasEnvironments = true;
                    if (environment.Equals(currentEnvironmentName, StringComparison.OrdinalIgnoreCase))
                    {
                        // Matching environment name found, do nothing
                        return;
                    }
                }
            }

            if (hasEnvironments)
            {
                // This instance had at least one non-empty environment specified but none of these
                // environments matched the current environment. Suppress the output in this case.
                output.SuppressOutput();
            }
        }
Exemplo n.º 9
0
        public void RepeatedStringIsTokenizedCorrectly()
        {
            const string toTokenize = "First\tFirstly\tThird";
            StringTokenizer tokenizer = new StringTokenizer(toTokenize);

            Assert.IsTrue(tokenizer.HasMoreTokens());
            Assert.AreEqual("First", tokenizer.NextToken());

            Assert.IsTrue(tokenizer.HasMoreTokens());
            Assert.AreEqual("Firstly", tokenizer.NextToken());

            Assert.IsTrue(tokenizer.HasMoreTokens());
            Assert.AreEqual("Third", tokenizer.NextToken());

            Assert.IsFalse(tokenizer.HasMoreTokens());
        }
Exemplo n.º 10
0
		public void StringIsTokenizedWithSpecifiedDelimiters()
		{
			const string toTokenize = "First,Second,Third";
			StringTokenizer tokenizer = new StringTokenizer(toTokenize, ",");

			Assert.IsTrue(tokenizer.HasMoreTokens());
			Assert.AreEqual("First", tokenizer.NextToken());

			Assert.IsTrue(tokenizer.HasMoreTokens());
			Assert.AreEqual("Second", tokenizer.NextToken());

			Assert.IsTrue(tokenizer.HasMoreTokens());
			Assert.AreEqual("Third", tokenizer.NextToken());

			Assert.IsFalse(tokenizer.HasMoreTokens());
		}
Exemplo n.º 11
0
        public void ChangingDelimitersIsHandledCorrectly()
        {
            const string toTokenize = "First,more\tSecond,Third";
            StringTokenizer tokenizer = new StringTokenizer(toTokenize);

            Assert.IsTrue(tokenizer.HasMoreTokens());
            Assert.AreEqual("First,more", tokenizer.NextToken());

            Assert.IsTrue(tokenizer.HasMoreTokens());
            Assert.AreEqual("Second", tokenizer.NextToken(","));

            Assert.IsTrue(tokenizer.HasMoreTokens());
            Assert.AreEqual("Third", tokenizer.NextToken());

            Assert.IsFalse(tokenizer.HasMoreTokens());
        }
Exemplo n.º 12
0
		public void StringIsTokenizedWithDefaultDelimiters()
		{
			const string toTokenize = "First\tSecond\tThird";
			StringTokenizer tokenizer = new StringTokenizer(toTokenize);

			Assert.IsTrue(tokenizer.HasMoreTokens());
			Assert.AreEqual("First", tokenizer.NextToken());

			Assert.IsTrue(tokenizer.HasMoreTokens());
			Assert.AreEqual("Second", tokenizer.NextToken());

			Assert.IsTrue(tokenizer.HasMoreTokens());
			Assert.AreEqual("Third", tokenizer.NextToken());

			Assert.IsFalse(tokenizer.HasMoreTokens());
		}
Exemplo n.º 13
0
    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
      if (value is Brush)
      {
        return value;
      }

      if (value is string)
      {
        StringTokenizer tokens = new StringTokenizer((string)value);

        if (tokens.Count == 1)
        {
          return ParseSolidColor(tokens[0]);
        }

        if (tokens.Count == 0)
        {
          return base.ConvertFrom(context, culture, value);
        }

        // http://winfx.msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/C_System_Windows_Media_LinearGradientBrush_ctor_2_ecb3b488.asp

        if (string.Compare(tokens[0], "HorizontalGradient", true) == 0)
        {
          return ParseHorizontalGradient(tokens);
        }

        if (string.Compare(tokens[0], "LinearGradient", true) == 0)
        {
          return ParseLinearGradient(tokens);
        }

        if (string.Compare(tokens[0], "VerticalGradient", true) == 0)
        {
          return ParseVerticalGradient(tokens);
        }

        throw new NotImplementedException();
      }

      return base.ConvertFrom(context, culture, value);
    }
Exemplo n.º 14
0
        public void CountIsCorrect()
        {
            const string toTokenize = "First\tSecond\tThird";
            StringTokenizer tokenizer = new StringTokenizer(toTokenize);

            Assert.AreEqual(3, tokenizer.Count);

            tokenizer.NextToken();
            Assert.AreEqual(2, tokenizer.Count);

            tokenizer.NextToken();
            Assert.AreEqual(1, tokenizer.Count);

            string token = tokenizer.NextToken();
            // This assert assures that asking for the count does not
            // affect the tokens themselves.
            Assert.AreEqual("Third", token);
            Assert.AreEqual(0, tokenizer.Count);
        }
Exemplo n.º 15
0
        public static string RenderOrderByStringTemplate(string sqlOrderByString, Dialect.Dialect dialect,
                                                         SQLFunctionRegistry functionRegistry)
        {
            //TODO: make this a bit nicer
            string symbols = new StringBuilder()
                             .Append("=><!+-*/()',|&`")
                             .Append(ParserHelper.Whitespace)
                             .Append(dialect.OpenQuote)
                             .Append(dialect.CloseQuote)
                             .ToString();
            StringTokenizer tokens = new StringTokenizer(sqlOrderByString, symbols, true);

            StringBuilder result           = new StringBuilder();
            bool          quoted           = false;
            bool          quotedIdentifier = false;

            using (var tokensEnum = tokens.GetEnumerator())
            {
                var hasMore   = tokensEnum.MoveNext();
                var nextToken = hasMore ? tokensEnum.Current : null;
                while (hasMore)
                {
                    var token   = nextToken;
                    var lcToken = token.ToLowerInvariant();
                    hasMore   = tokensEnum.MoveNext();
                    nextToken = hasMore ? tokensEnum.Current : null;

                    var isQuoteCharacter = false;

                    if (!quotedIdentifier && "'".Equals(token))
                    {
                        quoted           = !quoted;
                        isQuoteCharacter = true;
                    }

                    if (!quoted)
                    {
                        bool isOpenQuote;
                        if ("`".Equals(token))
                        {
                            isOpenQuote      = !quotedIdentifier;
                            token            = lcToken = isOpenQuote ? dialect.OpenQuote.ToString() : dialect.CloseQuote.ToString();
                            quotedIdentifier = isOpenQuote;
                            isQuoteCharacter = true;
                        }
                        else if (!quotedIdentifier && (dialect.OpenQuote == token[0]))
                        {
                            isOpenQuote      = true;
                            quotedIdentifier = true;
                            isQuoteCharacter = true;
                        }
                        else if (quotedIdentifier && (dialect.CloseQuote == token[0]))
                        {
                            quotedIdentifier = false;
                            isQuoteCharacter = true;
                            isOpenQuote      = false;
                        }
                        else
                        {
                            isOpenQuote = false;
                        }

                        if (isOpenQuote)
                        {
                            result.Append(Placeholder).Append('.');
                        }
                    }

                    var quotedOrWhitespace = quoted ||
                                             quotedIdentifier ||
                                             isQuoteCharacter ||
                                             char.IsWhiteSpace(token[0]);

                    if (quotedOrWhitespace)
                    {
                        result.Append(token);
                    }
                    else if (
                        IsIdentifier(token, dialect) &&
                        !IsFunctionOrKeyword(lcToken, nextToken, dialect, functionRegistry)
                        )
                    {
                        result.Append(Placeholder)
                        .Append('.')
                        .Append(token);
                    }
                    else
                    {
                        result.Append(token);
                    }
                }
            }
            return(result.ToString());
        }
Exemplo n.º 16
0
        public static string ResolvePath(string path)
        {
            Debug.Assert(!string.IsNullOrEmpty(path));
            var pathSegment = new StringSegment(path);

            if (path[0] == PathSeparators[0] || path[0] == PathSeparators[1])
            {
                // Leading slashes (e.g. "/Views/Index.cshtml") always generate an empty first token. Ignore these
                // for purposes of resolution.
                pathSegment = pathSegment.Subsegment(1);
            }

            var tokenizer          = new StringTokenizer(pathSegment, PathSeparators);
            var requiresResolution = false;

            foreach (var segment in tokenizer)
            {
                // Determine if we need to do any path resolution.
                // We need to resolve paths with multiple path separators (e.g "//" or "\\") or, directory traversals e.g. ("../" or "./").
                if (segment.Length == 0 ||
                    segment.Equals(ParentDirectoryToken, StringComparison.Ordinal) ||
                    segment.Equals(CurrentDirectoryToken, StringComparison.Ordinal))
                {
                    requiresResolution = true;
                    break;
                }
            }

            if (!requiresResolution)
            {
                return(path);
            }

            var pathSegments = new List <StringSegment>();

            foreach (var segment in tokenizer)
            {
                if (segment.Length == 0)
                {
                    // Ignore multiple directory separators
                    continue;
                }
                if (segment.Equals(ParentDirectoryToken, StringComparison.Ordinal))
                {
                    if (pathSegments.Count == 0)
                    {
                        // Don't resolve the path if we ever escape the file system root. We can't reason about it in a
                        // consistent way.
                        return(path);
                    }
                    pathSegments.RemoveAt(pathSegments.Count - 1);
                }
                else if (segment.Equals(CurrentDirectoryToken, StringComparison.Ordinal))
                {
                    // We already have the current directory
                    continue;
                }
                else
                {
                    pathSegments.Add(segment);
                }
            }

            var builder = new StringBuilder();

            for (var i = 0; i < pathSegments.Count; i++)
            {
                var segment = pathSegments[i];
                builder.Append('/');
                builder.Append(segment.Buffer, segment.Offset, segment.Length);
            }

            return(builder.ToString());
        }
Exemplo n.º 17
0
        public int Compare(string x, string y)
        {
            // < 0 = x < y
            // > 0 = x > y

            if (string.Equals(x, y, StringComparison.Ordinal))
            {
                return(0);
            }

            if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y))
            {
                return(string.Compare(x, y, StringComparison.Ordinal));
            }

            var xExtIndex = x.LastIndexOf('.');
            var yExtIndex = y.LastIndexOf('.');

            // Ensure extension index is in the last segment, i.e. in the file name
            var xSlashIndex = x.LastIndexOf('/');
            var ySlashIndex = y.LastIndexOf('/');

            xExtIndex = xExtIndex > xSlashIndex ? xExtIndex : -1;
            yExtIndex = yExtIndex > ySlashIndex ? yExtIndex : -1;

            // Get paths without their extensions, if they have one
            var xLength       = xExtIndex >= 0 ? xExtIndex : x.Length;
            var yLength       = yExtIndex >= 0 ? yExtIndex : y.Length;
            var compareLength = Math.Max(xLength, yLength);

            // In the resulting sequence, we want shorter paths to appear prior to longer paths. For paths of equal
            // depth, we'll compare individual segments. The first segment that differs determines the result.
            // For e.g.
            // Foo.cshtml < Foo.xhtml
            // Bar.cshtml < Foo.cshtml
            // ZZ/z.txt < A/A/a.txt
            // ZZ/a/z.txt < ZZ/z/a.txt

            if (string.Compare(x, 0, y, 0, compareLength, StringComparison.Ordinal) == 0)
            {
                // Only extension differs so just compare the extension
                if (xExtIndex >= 0 && yExtIndex >= 0)
                {
                    var length = x.Length - xExtIndex;
                    return(string.Compare(x, xExtIndex, y, yExtIndex, length, StringComparison.Ordinal));
                }

                return(xExtIndex - yExtIndex);
            }

            var xNoExt = xExtIndex >= 0 ? x.Substring(0, xExtIndex) : x;
            var yNoExt = yExtIndex >= 0 ? y.Substring(0, yExtIndex) : y;

            var           result      = 0;
            var           xEnumerator = new StringTokenizer(xNoExt, PathSeparator).GetEnumerator();
            var           yEnumerator = new StringTokenizer(yNoExt, PathSeparator).GetEnumerator();
            StringSegment ySegment;

            while (TryGetNextSegment(ref xEnumerator, out var xSegment))
            {
                if (!TryGetNextSegment(ref yEnumerator, out ySegment))
                {
                    // Different path depths (right is shorter), so shallower path wins.
                    return(1);
                }

                if (result != 0)
                {
                    // Once we've determined that a segment differs, we need to ensure that the two paths
                    // are of equal depth.
                    continue;
                }

                var length = Math.Max(xSegment.Length, ySegment.Length);
                result = string.Compare(
                    xSegment.Buffer,
                    xSegment.Offset,
                    ySegment.Buffer,
                    ySegment.Offset,
                    length,
                    StringComparison.Ordinal);
            }

            if (TryGetNextSegment(ref yEnumerator, out ySegment))
            {
                // Different path depths (left is shorter). Shallower path wins.
                return(-1);
            }
            else
            {
                // Segments are of equal length
                return(result);
            }
        }
Exemplo n.º 18
0
        public override string ParseString(string strValue)
        {
            GEDCOMFormat format = GEDCOMProvider.GetGEDCOMFormat(Owner);

            fApproximated = GEDCOMApproximated.daExact;
            fCalendar     = GEDCOMCalendar.dcGregorian;
            fYear         = UNKNOWN_YEAR;
            fYearBC       = false;
            fYearModifier = "";
            fMonth        = "";
            fDay          = 0;

            if (!string.IsNullOrEmpty(strValue))
            {
                if (format == GEDCOMFormat.gf_Ahnenblatt)
                {
                    strValue = PrepareAhnenblattDate(strValue);
                }

                var strTok = new StringTokenizer(strValue);
                strTok.IgnoreWhiteSpace = false;
                strTok.Next();
                strTok.SkipWhiteSpaces();

                // extract approximated
                var token = strTok.CurrentToken;
                if (token.Kind == TokenKind.Word)
                {
                    string su  = token.Value.ToUpperInvariant();
                    int    idx = Algorithms.IndexOf(GEDCOMDateApproximatedArray, su);
                    if (idx >= 0)
                    {
                        fApproximated = (GEDCOMApproximated)idx;
                        strTok.Next();
                        strTok.SkipWhiteSpaces();
                    }
                }

                // extract escape
                token = strTok.CurrentToken;
                if (token.Kind == TokenKind.Symbol && token.Value[0] == '@')
                {
                    var escapeStr = token.Value;
                    do
                    {
                        token      = strTok.Next();
                        escapeStr += token.Value;
                    } while (token.Kind != TokenKind.Symbol || token.Value[0] != '@');
                    // FIXME: check for errors

                    int idx = Algorithms.IndexOf(GEDCOMDateEscapeArray, escapeStr);
                    if (idx >= 0)
                    {
                        fCalendar = (GEDCOMCalendar)idx;
                    }

                    strTok.Next();
                    strTok.SkipWhiteSpaces();
                }

                // extract day
                token = strTok.CurrentToken;
                if (token.Kind == TokenKind.Number && token.Value.Length <= 2)
                {
                    fDay  = (byte)(int)token.ValObj;
                    token = strTok.Next();
                }

                // extract delimiter
                if (token.Kind == TokenKind.WhiteSpace && token.Value[0] == ' ')
                {
                    fDateFormat = GEDCOMDateFormat.dfGEDCOMStd;
                    token       = strTok.Next();
                }
                else if (token.Kind == TokenKind.Symbol && token.Value[0] == '.')
                {
                    fDateFormat = GEDCOMDateFormat.dfSystem;
                    token       = strTok.Next();
                }

                // extract month
                string[] monthes = GetMonthNames(fCalendar);
                if (token.Kind == TokenKind.Word)
                {
                    string mth = token.Value;

                    int idx = Algorithms.IndexOf(monthes, mth);
                    if (idx >= 0)
                    {
                        fMonth = mth;
                    }

                    token = strTok.Next();
                }
                else if (fDateFormat == GEDCOMDateFormat.dfSystem && token.Kind == TokenKind.Number)
                {
                    int idx = (int)token.ValObj;
                    fMonth = monthes[idx - 1];

                    token = strTok.Next();
                }

                // extract delimiter
                if (fDateFormat == GEDCOMDateFormat.dfSystem)
                {
                    if (token.Kind == TokenKind.Symbol && token.Value[0] == '.')
                    {
                        token = strTok.Next();
                    }
                }
                else
                {
                    if (token.Kind == TokenKind.WhiteSpace && token.Value[0] == ' ')
                    {
                        token = strTok.Next();
                    }
                }

                // extract year
                if (token.Kind == TokenKind.Number)
                {
                    fYear = (short)(int)token.ValObj;
                    token = strTok.Next();

                    // extract year modifier
                    if (token.Kind == TokenKind.Symbol && token.Value[0] == '/')
                    {
                        token = strTok.Next();
                        if (token.Kind != TokenKind.Number)
                        {
                            // error
                        }
                        fYearModifier = token.Value;
                        token         = strTok.Next();
                    }

                    // extract bc/ad
                    if (token.Kind == TokenKind.Word && token.Value[0] == 'B')
                    {
                        token = strTok.Next();
                        if (token.Kind != TokenKind.Symbol || token.Value[0] != '.')
                        {
                            // error
                        }
                        token = strTok.Next();
                        if (token.Kind != TokenKind.Word || token.Value[0] != 'C')
                        {
                            // error
                        }
                        token = strTok.Next();
                        if (token.Kind != TokenKind.Symbol || token.Value[0] != '.')
                        {
                            // error
                        }
                        strTok.Next();
                        fYearBC = true;
                    }
                }

                strValue = strTok.GetRest();
            }

            DateChanged();

            return(strValue);
        }
Exemplo n.º 19
0
        public string Process(TextTokenHandlerBase behaviour)
        {
            if (behaviour == null)
            {
                throw new ArgumentNullException("behaviour");
            }

            // define which character is separating fields

            var parser = new StringTokenizer(_sqlStatement, ELEMENT_TOKEN, true);

            var    newSql = new StringBuilder();
            var    keepSurroundingToken = behaviour.KeepSurroundingToken;
            string lastToken            = null;

            IEnumerator enumerator = parser.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string token = ((string)enumerator.Current);

                if (ELEMENT_TOKEN.Equals(lastToken))
                {
                    if (ELEMENT_TOKEN.Equals(token))
                    {
                        newSql.Append(ELEMENT_TOKEN);
                        token = null;
                    }
                    else
                    {
                        var value = behaviour.ProcessToken(token);

                        if (value != null)
                        {
                            if (keepSurroundingToken)
                            {
                                newSql.Append(ELEMENT_TOKEN + value + ELEMENT_TOKEN);
                            }
                            else
                            {
                                newSql.Append(value);
                            }
                        }

                        enumerator.MoveNext();

                        token = ((string)enumerator.Current);

                        if (!ELEMENT_TOKEN.Equals(token))
                        {
                            throw new DataMapperException("Unterminated dynamic element in sql (" + _sqlStatement + ").");
                        }
                        token = null;
                    }
                }
                else
                {
                    if (!ELEMENT_TOKEN.Equals(token))
                    {
                        newSql.Append(token);
                    }
                }

                lastToken = token;
            }

            return(behaviour.PostProcessing(newSql.ToString()));
        }
Exemplo n.º 20
0
        public VerilogModuleInstance ParseModuleInstance(VerilogModule parent, StringTokenizer tknzr, Token possibleParamList, VerilogModule modInstType)
        {
            string instName;
            Token  paramListBegin = possibleParamList;//tknzr.Next();
            bool   paramExists    = false;
            bool   paramsNamed    = false;
            string word           = tknzr.Next().Value;

            if (word == "#")
            {
                // Run through parameter lists until parens all closed
                paramExists = true;
                //paramListBegin =
                tknzr.Next(); // after "#("
                int parenPairs = 1;
                while (parenPairs > 0)
                {
                    word = tknzr.Next().Value;
                    if (word.Contains("."))
                    {
                        paramsNamed = true;
                    }
                    if (word == "(")
                    {
                        parenPairs++;
                    }
                    else if (word == ")")
                    {
                        parenPairs--;
                    }
                }
                instName = tknzr.Next().Value;
            }
            else
            {
                instName = word;
            }

            if (instName.Contains("st4_rrobin") || parent.Name == "lsu_rrobin_picker2")
            {
                Console.Write("pOOp");
            }

            Token currTok    = tknzr.Next();
            Token prevTok    = currTok;
            Token twoPrevTok = currTok;

            while (currTok.Value != ";")
            {
                // Run through in/out list to end of instantiation
                twoPrevTok = prevTok;      // At ')'
                prevTok    = currTok;      // At ';'
                currTok    = tknzr.Next(); // After ';'
            }
            VerilogModuleInstance vModInst = modInstType.Instantiate(parent, instName, twoPrevTok);

            vModInst.ParameterList   = paramListBegin;
            vModInst.Parameterized   = paramExists;
            vModInst.ParametersNamed = paramsNamed;
            return(vModInst);
        }
Exemplo n.º 21
0
 private Boolean RunPrecompiler(StringTokenizer tknzr, ref Token prevTok, ref Token currTok)
 {
     if (currTok.Value != "`")
     {
         return(false);
     }
     // PRECOMPILER DIRECTIVE FOUND
     prevTok = currTok;
     currTok = tknzr.Next();
     if (currTok.Value == "ifdef")
     {
         prevTok = currTok;
         currTok = tknzr.Next();
         if (defineSet.Contains(currTok.Value))
         {
             //PARSE: If it is defined, parse the ifdef
             ifdefStack.Push(currTok.Value + "@" + currTok.Line + ":" + currTok.Column);
         }
         else
         {
             //IGNORE: Seek to end or else
             int ifdefCount = 0;
             while (true)
             {
                 if (currTok.Kind == TokenKind.EOF)
                 {
                     break;
                 }
                 prevTok = currTok;
                 currTok = tknzr.Next();
                 if (currTok.Value == "ifdef")
                 {
                     ifdefCount++;
                 }
                 else if (currTok.Value == "else" && ifdefCount == 0)
                 {
                     break;
                 }
                 else if (currTok.Value == "endif")
                 {
                     if (ifdefCount > 0)
                     {
                         ifdefCount--;
                     }
                     else
                     {
                         break;
                     }
                 }
             }
             if (currTok.Value == "else")
             {
                 ifdefStack.Push(currTok.Value + "@" + currTok.Line + ":" + currTok.Column);
             }
         }
     }
     else if (currTok.Value == "else")
     {
         // IGNORE:
         int ifdefCount = 0;
         while (true)
         {
             if (currTok.Kind == TokenKind.EOF)
             {
                 break;
             }
             prevTok = currTok;
             currTok = tknzr.Next();
             if (currTok.Value == "ifdef")
             {
                 ifdefCount++;
             }
             else if (currTok.Value == "endif")
             {
                 if (ifdefCount > 0)
                 {
                     ifdefCount--;
                 }
                 else
                 {
                     break;
                 }
             }
         }
         //ifdefStack.Pop();
     }
     else if (currTok.Value == "endif")
     {
         // PARSE:
         //ifdefStack.Pop();
     }
     else if (currTok.Value == "define")
     {
         prevTok = currTok;
         currTok = tknzr.Next();
         defineSet.Add(currTok.Value);
     }
     prevTok = currTok;
     currTok = tknzr.Next();
     return(true);
 }
Exemplo n.º 22
0
        private DffInstance ParseDffInstance(StringTokenizer tknzr, Token possibleParameter, DFFModule dffType)
        {
            DffInstance dff       = new DffInstance(dffType);
            Token       currToken = tknzr.Next();

            dff.ParameterBegin  = possibleParameter;
            dff.ParametersExist = false;
            dff.ParametersNamed = false;
            dff.ParamsInParens  = false;
            if (currToken.Value == "#")
            {
                dff.ParametersExist = true;
                dff.ParameterBegin  = currToken;
                currToken           = tknzr.Next();
                if (currToken.Value == "(")
                {
                    dff.ParamsInParens = true;
                    dff.ParameterBegin = currToken;
                    Token  tempParamList;
                    string paramValue = tknzr.ParseToCloseParenthesis(out tempParamList);
                    dff.ParameterList = tempParamList;
                    dff.ParameterEnd  = tempParamList;
                    try {
                        dff.Size = Convert.ToInt32(paramValue);
                    } catch (FormatException) {
                        if (paramValue.StartsWith("`"))
                        {
                            // TODO: Deal with `DEFINE'd values
                            dff.Size = 1;
                        }
                        else if (paramValue.StartsWith("."))
                        {
                            dff.ParametersNamed = true;
                        }
                        else
                        {
                            dff.ParametersExist = true;
                            dff.IsParameterized = true;
                            dff.Parameter       = paramValue;
                            //throw new InvalidDataException("Wah. I don't get it. '" + currToken.Value + "' isn't a number.");
                        }
                    }
                }
                else
                {
                    dff.ParameterEnd = currToken;
                    try {
                        dff.Size = Convert.ToInt32(currToken.Value); // In case they use the weird '#12' notation instead of '#(12)'
                    } catch (FormatException) {
                        if (currToken.Value == "`")
                        {
                            // TODO: Deal with `DEFINE'd values
                            dff.Size = 1;
                        }
                        else
                        {
                            throw new InvalidDataException("Wah. I don't get it. '" + currToken.Value + "' isn't a number.");
                        }
                    }
                }

                //tknzr.Next();
                currToken        = tknzr.Next();
                dff.InstanceName = currToken.Value;
            }
            else
            {
                dff.Size         = 1;
                dff.InstanceName = currToken.Value;
            }

            while (currToken.Value != "(")
            {
                currToken = tknzr.Next();
            }
            //currToken = tknzr.Next();
            dff.PortList = currToken;

            while (dff.ClockPort == null || dff.DPort == null || dff.QPort == null)
            {
                currToken = tknzr.Next();
                string word = currToken.Value;
                if (word == ";")
                {
                    break;
                }
                if (word == ".")
                {
                    currToken = tknzr.Next();
                    switch (currToken.Value)
                    {
                    case "clk": {
                        tknzr.Next();
                        Token tempToken;
                        dff.ClockPort = tknzr.ParseToCloseParenthesis(out tempToken);
                        break;
                    }

                    case "q": {
                        tknzr.Next();
                        Token tempToken;
                        dff.QPort = tknzr.ParseToCloseParenthesis(out tempToken);
                        break;
                    }

                    case "din": {
                        tknzr.Next();
                        Token tempToken;
                        dff.DPort = tknzr.ParseToCloseParenthesis(out tempToken);
                        break;
                    }
                    }
                }
            }
            while (currToken.Value != ";" && currToken.Kind != TokenKind.EOF)
            {
                currToken = tknzr.Next();
            }
            return(dff);
        }
Exemplo n.º 23
0
        private VerilogModule ParseModuleDeclaration(StringTokenizer tknzr, VerilogFile vFile)
        {
            #region Are the ports even needed? Besides knowing where to insert the shadow chain ports

            /*
             * List<string> inPorts = new List<string>();
             * List<string> outPorts = new List<string>();
             * List<string> inoutPorts = new List<string>();
             * Token currToken = null;
             * Token prevToken = new Token(TokenKind.Unknown, "", 0, 0, 0);
             * while (true) {
             *  if (currToken == null) {
             *      tknzr.Next();
             *  }
             *  currToken = tknzr.Next();
             *  if (currToken.Kind == TokenKind.EOF) {
             *      break;
             *  } else if (currToken.Value == ";" && prevToken.Value == ")") {
             *      break;
             *  } else if (currToken.Value == "input" && prevToken.Kind == TokenKind.EOL) {
             *
             *  }
             *  prevToken = currToken;
             * }
             */
            #endregion
            Token         prevTok      = tknzr.Next();
            Token         twoPrevTok   = prevTok;
            Token         currTok      = tknzr.Next();
            VerilogModule vMod         = new VerilogModule(vFile.FileName, prevTok.Value);
            bool          headerParsed = false;
            while (currTok.Value != "endmodule" && currTok.Kind != TokenKind.EOF)
            {
                if (prevTok.Kind == TokenKind.EOL)
                {
                    if (!RunPrecompiler(tknzr, ref prevTok, ref currTok))
                    {
                        if (currTok.Value == "parameter")
                        {
                            // PARAMETER FOUND
                            ParseParameter(tknzr, vMod.Parameters);
                        }
                        else if (this.project.IsDff(currTok.Value))
                        {
                            // DFF INSTANCE FOUND
                            DffInstance dffInst = ParseDffInstance(tknzr, currTok, project.GetDffType(currTok.Value));
                            if (dffInst == null)
                            {
                                throw new InvalidDataException("DFF Library was unable to instantiate from type retrieved from project.");
                            }
                            vMod.AddDffInstance(dffInst);
                        }
                        else if (this.project.IsModule(currTok.Value))
                        {
                            // MODULE INSTANCE FOUND
                            VerilogModuleInstance vModInst = ParseModuleInstance(vMod, tknzr, currTok, project.GetModule(currTok.Value));
                            if (vModInst == null)
                            {
                                throw new InvalidDataException("Error instantiating module from type retrieved from project.");
                            }
                            vMod.AddModuleInstance(vModInst);
                        }
                        else if (headerParsed && !this.project.IsKeyword(currTok.Value) && currTok.Kind == TokenKind.Word)
                        {
                            // POSSIBLE MODULE, NOT YET PARSED

                            /* OPTIMZATION:
                             * TODO: Change tokenizer to ignore everything between certain keywords and ';',
                             * EX: "assign blah = blah blah blah;" in case there is weird indenting for
                             * readibility. This will minimize the number of false Possibles.
                             * */
                            if (currTok.Value == "lsu_dc_parity_gen")
                            {
                                Console.Write("!");
                            }
                            StringTokenizer tempTknzr  = new StringTokenizer(tknzr); // Perform deep copy to leave tknzr untouched
                            Token           nameTok    = tempTknzr.Next();
                            bool            paramExist = false;
                            bool            paramNamed = false;
                            Token           paramList  = null;

                            /*if (nameTok.Value == "#") {
                             *  paramsExist = true;
                             *  tempTknzr.Next();// (
                             *  tempTknzr.Next();// Number
                             *  tempTknzr.Next();// )
                             *  nameTok = tempTknzr.Next();
                             * }*/

                            if (nameTok.Value == "#")
                            {
                                // Run through parameter lists until parens all closed
                                paramExist = true;
                                paramList  = tempTknzr.Next(); // after "#("
                                if (paramList.Value == "(")
                                {
                                    int parenPairs = 1;
                                    while (parenPairs > 0)
                                    {
                                        nameTok = tempTknzr.Next();
                                        if (nameTok.Value.Contains("."))
                                        {
                                            paramNamed = true;
                                        }
                                        if (nameTok.Value == "(")
                                        {
                                            parenPairs++;
                                        }
                                        else if (nameTok.Value == ")")
                                        {
                                            parenPairs--;
                                        }
                                    }
                                }
                                nameTok = tempTknzr.Next();
                            }
                            else
                            {
                                paramList = currTok;
                            }
                            Token tempCurrTok    = tempTknzr.Next();
                            Token tempPrevTok    = tempCurrTok;
                            Token tempTwoPrevTok = tempCurrTok;
                            while (tempCurrTok.Value != ";")
                            {
                                // Run through in/out list to end of instantiation
                                tempTwoPrevTok = tempPrevTok;      // At ')'
                                tempPrevTok    = tempCurrTok;      // At ';'
                                tempCurrTok    = tempTknzr.Next(); // After ';'
                            }
                            vMod.AddPossibleInstance(currTok, nameTok.Value, tempTwoPrevTok, paramExist, paramNamed, paramList);
                        }
                    }
                }
                twoPrevTok = prevTok;
                prevTok    = currTok;
                currTok    = tknzr.Next();
                if (!headerParsed && currTok.Value == ";" /*&& prevTok.Value == ")"*/)
                {
                    vMod.InOutListEnd = twoPrevTok;
                    vMod.PostHeader   = tknzr.Next();
                    twoPrevTok        = prevTok;
                    prevTok           = (currTok.Value == ")")? currTok : prevTok;
                    currTok           = vMod.PostHeader;
                    headerParsed      = true;
                }
            }
            vMod.PrevEndModule = prevTok;
            return(vMod);
        }
Exemplo n.º 24
0
        public static string RenderWhereStringTemplate(string sqlWhereString, string placeholder, Dialect.Dialect dialect,
                                                       SQLFunctionRegistry functionRegistry)
        {
            //TODO: make this a bit nicer
            string symbols = new StringBuilder()
                             .Append("=><!+-*/()',|&`")
                             .Append(ParserHelper.Whitespace)
                             .Append(dialect.OpenQuote)
                             .Append(dialect.CloseQuote)
                             .ToString();
            StringTokenizer tokens = new StringTokenizer(sqlWhereString, symbols, true);

            StringBuilder result           = new StringBuilder();
            bool          quoted           = false;
            bool          quotedIdentifier = false;
            bool          beforeTable      = false;
            bool          inFromClause     = false;
            bool          afterFromTable   = false;

            using (var tokensEnum = tokens.GetEnumerator())
            {
                var hasMore   = tokensEnum.MoveNext();
                var nextToken = hasMore ? tokensEnum.Current : null;
                var lastToken = string.Empty;
                while (hasMore)
                {
                    var token   = nextToken;
                    var lcToken = token.ToLowerInvariant();
                    hasMore   = tokensEnum.MoveNext();
                    nextToken = hasMore ? tokensEnum.Current : null;

                    var isQuoteCharacter = false;

                    if (!quotedIdentifier && "'".Equals(token))
                    {
                        quoted           = !quoted;
                        isQuoteCharacter = true;
                    }

                    if (!quoted)
                    {
                        bool isOpenQuote;
                        if ("`".Equals(token))
                        {
                            isOpenQuote      = !quotedIdentifier;
                            token            = lcToken = isOpenQuote ? dialect.OpenQuote.ToString() : dialect.CloseQuote.ToString();
                            quotedIdentifier = isOpenQuote;
                            isQuoteCharacter = true;
                        }
                        else if (!quotedIdentifier && (dialect.OpenQuote == token[0]))
                        {
                            isOpenQuote      = true;
                            quotedIdentifier = true;
                            isQuoteCharacter = true;
                        }
                        else if (quotedIdentifier && (dialect.CloseQuote == token[0]))
                        {
                            quotedIdentifier = false;
                            isQuoteCharacter = true;
                            isOpenQuote      = false;
                        }
                        else
                        {
                            isOpenQuote = false;
                        }

                        if (isOpenQuote && !inFromClause && !lastToken.EndsWith("."))
                        {
                            result.Append(placeholder).Append('.');
                        }
                    }

                    var quotedOrWhitespace = quoted ||
                                             quotedIdentifier ||
                                             isQuoteCharacter ||
                                             char.IsWhiteSpace(token[0]);

                    if (quotedOrWhitespace)
                    {
                        result.Append(token);
                    }
                    else if (beforeTable)
                    {
                        result.Append(token);
                        beforeTable    = false;
                        afterFromTable = true;
                    }
                    else if (afterFromTable)
                    {
                        if (!"as".Equals(lcToken))
                        {
                            afterFromTable = false;
                        }
                        result.Append(token);
                    }
                    else if (IsNamedParameter(token))
                    {
                        result.Append(token);
                    }
                    else if (
                        IsIdentifier(token, dialect) &&
                        !IsFunctionOrKeyword(lcToken, nextToken, dialect, functionRegistry)
                        )
                    {
                        result.Append(placeholder)
                        .Append('.')
                        .Append(token);
                    }
                    else
                    {
                        if (BeforeTableKeywords.Contains(lcToken))
                        {
                            beforeTable  = true;
                            inFromClause = true;
                        }
                        else if (inFromClause && ",".Equals(lcToken))
                        {
                            beforeTable = true;
                        }
                        result.Append(token);
                    }

                    if (                              //Yuck:
                        inFromClause &&
                        Keywords.Contains(lcToken) && //"as" is not in Keywords
                        !BeforeTableKeywords.Contains(lcToken)
                        )
                    {
                        inFromClause = false;
                    }
                    lastToken = token;
                }
            }
            return(result.ToString());
        }
		/// <summary>
		/// Parse inline parameter with syntax as
		/// #propertyName:dbType:nullValue#
		/// </summary>
		/// <param name="token"></param>
		/// <param name="parameterClassType"></param>
		/// <param name="scope"></param>
		/// <returns></returns>
		private ParameterProperty OldParseMapping(string token, Type parameterClassType, IScope scope) 
		{
			ParameterProperty mapping = null;
            string propertyName = string.Empty;
            string dbType = string.Empty;
            string nullValue = string.Empty;

			if (token.IndexOf(PARAM_DELIM) > -1) 
			{
				StringTokenizer paramParser = new StringTokenizer(token, PARAM_DELIM, true);
				IEnumerator enumeratorParam = paramParser.GetEnumerator();

				int n1 = paramParser.TokenNumber;
				if (n1 == 3) 
				{
					enumeratorParam.MoveNext();
					propertyName = ((string)enumeratorParam.Current).Trim();

					enumeratorParam.MoveNext();
					enumeratorParam.MoveNext(); //ignore ":"
                    dbType = ((string)enumeratorParam.Current).Trim();

                    //ITypeHandler handler = null;
                    //if (parameterClassType == null) 
                    //{
                    //    handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    //} 
                    //else 
                    //{
                    //    handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, propertyName, null, dBType);
                    //}
                    //mapping.TypeHandler = handler;
                    //mapping.Initialize( scope, parameterClassType );
				} 
				else if (n1 >= 5) 
				{
					enumeratorParam.MoveNext();
					propertyName = ((string)enumeratorParam.Current).Trim();

					enumeratorParam.MoveNext();
					enumeratorParam.MoveNext(); //ignore ":"
                    dbType = ((string)enumeratorParam.Current).Trim();

					enumeratorParam.MoveNext();
					enumeratorParam.MoveNext(); //ignore ":"
					nullValue = ((string)enumeratorParam.Current).Trim();

					while (enumeratorParam.MoveNext()) 
					{
						nullValue = nullValue + ((string)enumeratorParam.Current).Trim();
					}

                    //ITypeHandler handler = null;
                    //if (parameterClassType == null) 
                    //{
                    //    handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    //} 
                    //else 
                    //{
                    //    handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, propertyName, null, dBType);
                    //}
                    //mapping.TypeHandler = handler;
                    //mapping.Initialize( scope, parameterClassType );
				} 
				else 
				{
					throw new ConfigurationException("Incorrect inline parameter map format: " + token);
				}
			} 
			else 
			{
				propertyName = token;
                //ITypeHandler handler = null;
                //if (parameterClassType == null) 
                //{
                //    handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                //} 
                //else 
                //{
                //    handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, token, null, null);
                //}
                //mapping.TypeHandler = handler;
                //mapping.Initialize( scope, parameterClassType );


			}

            return new ParameterProperty(
                propertyName,
                string.Empty,
                string.Empty,
                string.Empty,
                dbType,
                string.Empty,
                nullValue,
                0,
                0,
                -1,
                parameterClassType,
                scope.DataExchangeFactory);
		}
Exemplo n.º 26
0
        /// <summary>
        /// Entry point to the Compile application.
        /// <para/>
        /// This program takes any number of arguments: the first is the name of the
        /// desired stemming algorithm to use (a list is available in the package
        /// description) , all of the rest should be the path or paths to a file or
        /// files containing a stemmer table to compile.
        /// </summary>
        /// <param name="args">the command line arguments</param>
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }

            // LUCENENET NOTE: This line does nothing in .NET
            // and also does nothing in Java...what?
            //args[0].ToUpperInvariant();

            // Reads the first char of the first arg
            backward = args[0][0] == '-';
            int  qq        = (backward) ? 1 : 0;
            bool storeorig = false;

            if (args[0][qq] == '0')
            {
                storeorig = true;
                qq++;
            }

            multi = args[0][qq] == 'M';
            if (multi)
            {
                qq++;
            }
            // LUCENENET specific - reformatted with : and changed "charset" to "encoding"
            string charset       = SystemProperties.GetProperty("egothor:stemmer:encoding", "UTF-8");
            var    stemmerTables = new List <string>();

            // LUCENENET specific
            // command line argument overrides environment variable or default, if supplied
            for (int i = 1; i < args.Length; i++)
            {
                if ("-e".Equals(args[i], StringComparison.Ordinal) || "--encoding".Equals(args[i], StringComparison.Ordinal))
                {
                    charset = args[i];
                }
                else
                {
                    stemmerTables.Add(args[i]);
                }
            }

            char[] optimizer = new char[args[0].Length - qq];
            for (int i = 0; i < optimizer.Length; i++)
            {
                optimizer[i] = args[0][qq + i];
            }

            foreach (var stemmerTable in stemmerTables)
            {
                // System.out.println("[" + args[i] + "]");
                Diff diff = new Diff();
                //int stems = 0; // not used
                int words = 0;


                AllocTrie();

                Console.WriteLine(stemmerTable);
                using (TextReader input = new StreamReader(
                           new FileStream(stemmerTable, FileMode.Open, FileAccess.Read), Encoding.GetEncoding(charset)))
                {
                    string line;
                    while ((line = input.ReadLine()) != null)
                    {
                        line = line.ToLowerInvariant();
                        using StringTokenizer st = new StringTokenizer(line);
                        if (st.MoveNext())
                        {
                            string stem = st.Current;
                            if (storeorig)
                            {
                                trie.Add(stem, "-a");
                                words++;
                            }
                            while (st.MoveNext())
                            {
                                string token = st.Current;
                                if (token.Equals(stem, StringComparison.Ordinal) == false)
                                {
                                    trie.Add(token, diff.Exec(token, stem));
                                    words++;
                                }
                            }
                        }
                        else // LUCENENET: st.MoveNext() will return false rather than throwing a NoSuchElementException
                        {
                            // no base token (stem) on a line
                        }
                    }
                }

                Optimizer  o  = new Optimizer();
                Optimizer2 o2 = new Optimizer2();
                Lift       l  = new Lift(true);
                Lift       e  = new Lift(false);
                Gener      g  = new Gener();

                for (int j = 0; j < optimizer.Length; j++)
                {
                    string prefix;
                    switch (optimizer[j])
                    {
                    case 'G':
                        trie   = trie.Reduce(g);
                        prefix = "G: ";
                        break;

                    case 'L':
                        trie   = trie.Reduce(l);
                        prefix = "L: ";
                        break;

                    case 'E':
                        trie   = trie.Reduce(e);
                        prefix = "E: ";
                        break;

                    case '2':
                        trie   = trie.Reduce(o2);
                        prefix = "2: ";
                        break;

                    case '1':
                        trie   = trie.Reduce(o);
                        prefix = "1: ";
                        break;

                    default:
                        continue;
                    }
                    trie.PrintInfo(Console.Out, prefix + " ");
                }

                using DataOutputStream os = new DataOutputStream(
                          new FileStream(stemmerTable + ".out", FileMode.OpenOrCreate, FileAccess.Write));
                os.WriteUTF(args[0]);
                trie.Store(os);
            }
        }
Exemplo n.º 27
0
    public SubtitleSelector(ISubtitleStream dvbStreams, SubtitleRenderer subRender, TeletextSubtitleDecoder subDecoder)
    {
      Log.Debug("SubtitleSelector ctor");
      if (subRender == null)
      {
        throw new Exception("Nullpointer input not allowed ( SubtitleRenderer)");
      }
      else
      {
        this.dvbStreams = dvbStreams;
        this.subRender = subRender;
      }

      // load preferences
      using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Config, "MediaPortal.xml")))
      {
        preferedLanguages = new List<string>();
        string languages = reader.GetValueAsString("tvservice", "preferredsublanguages", "");
        Log.Debug("SubtitleSelector: sublangs entry content: " + languages);
        StringTokenizer st = new StringTokenizer(languages, ";");
        while (st.HasMore)
        {
          string lang = st.NextToken();
          if (lang.Length != 3)
          {
            Log.Warn("Language {0} is not in the correct format!", lang);
          }
          else
          {
            preferedLanguages.Add(lang);
            Log.Info("Prefered language {0} is {1}", preferedLanguages.Count, lang);
          }
        }
      }

      pageEntries = new Dictionary<int, TeletextPageEntry>();

      bitmapSubtitleCache = new List<SubtitleOption>();

      lock (syncLock)
      {
        if (subDecoder != null)
        {
          subDecoder.SetPageInfoCallback(new MediaPortal.Player.Subtitles.TeletextSubtitleDecoder.PageInfoCallback(OnPageInfo));
        }

        if (dvbStreams != null)
        {
          RetrieveBitmapSubtitles();
          subStreamCallback = new SubtitleStreamEventCallback(OnSubtitleReset);
          IntPtr pSubStreamCallback = Marshal.GetFunctionPointerForDelegate(subStreamCallback);
          Log.Debug("Calling SetSubtitleStreamEventCallback");
          dvbStreams.SetSubtitleResetCallback(pSubStreamCallback);
        }

        if (preferedLanguages.Count > 0)
        {
          autoSelectOption = new SubtitleOption();
          autoSelectOption.language = "None";
          autoSelectOption.isAuto = true;
          autoSelectOption.type = SubtitleType.None;

          SetOption(0); // the autoselect mode will have index 0 (ugly)
        }
      }
      Log.Debug("End SubtitleSelector ctor");
    }
        public static object[] IterateOutlines(PdfWriter writer, PdfIndirectReference parent, ArrayList kids, bool namedAsNames)
        {
            PdfIndirectReference[] refs = new PdfIndirectReference[kids.Count];
            for (int k = 0; k < refs.Length; ++k)
            {
                refs[k] = writer.PdfIndirectReference;
            }
            int ptr   = 0;
            int count = 0;

            foreach (Hashtable map in kids)
            {
                object[]  lower  = null;
                ArrayList subKid = (ArrayList)map["Kids"];
                if (subKid != null && subKid.Count > 0)
                {
                    lower = IterateOutlines(writer, refs[ptr], subKid, namedAsNames);
                }
                PdfDictionary outline = new PdfDictionary();
                ++count;
                if (lower != null)
                {
                    outline.Put(PdfName.First, (PdfIndirectReference)lower[0]);
                    outline.Put(PdfName.Last, (PdfIndirectReference)lower[1]);
                    int n = (int)lower[2];
                    if ("false".Equals(map["Open"]))
                    {
                        outline.Put(PdfName.Count, new PdfNumber(-n));
                    }
                    else
                    {
                        outline.Put(PdfName.Count, new PdfNumber(n));
                        count += n;
                    }
                }
                outline.Put(PdfName.Parent, parent);
                if (ptr > 0)
                {
                    outline.Put(PdfName.Prev, refs[ptr - 1]);
                }
                if (ptr < refs.Length - 1)
                {
                    outline.Put(PdfName.Next, refs[ptr + 1]);
                }
                outline.Put(PdfName.Title, new PdfString((string)map["Title"], PdfObject.TEXT_UNICODE));
                string color = (string)map["Color"];
                if (color != null)
                {
                    try
                    {
                        PdfArray        arr = new PdfArray();
                        StringTokenizer tk  = new StringTokenizer(color);
                        for (int k = 0; k < 3; ++k)
                        {
                            float f = float.Parse(tk.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                            if (f < 0)
                            {
                                f = 0;
                            }
                            if (f > 1)
                            {
                                f = 1;
                            }
                            arr.Add(new PdfNumber(f));
                        }
                        outline.Put(PdfName.C, arr);
                    }
                    catch { } //in case it's malformed
                }
                string style = (string)map["Style"];
                if (style != null)
                {
                    int bits = 0;
                    if (style.IndexOf("italic", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        bits |= 1;
                    }
                    if (style.IndexOf("bold", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        bits |= 2;
                    }
                    if (bits != 0)
                    {
                        outline.Put(PdfName.F, new PdfNumber(bits));
                    }
                }
                CreateOutlineAction(outline, map, writer, namedAsNames);
                writer.AddToBody(outline, refs[ptr]);
                ++ptr;
            }
            return(new object[] { refs[0], refs[refs.Length - 1], count });
        }
Exemplo n.º 29
0
        private void LoadFromStream(Stream fileStream, StreamReader reader)
        {
            fTree.State = GEDCOMState.osLoading;
            try
            {
                ProgressEventHandler progressHandler = fTree.OnProgress;

                fSourceEncoding = DEFAULT_ENCODING;
                fEncodingState  = EncodingState.esUnchecked;
                long fileSize = fileStream.Length;
                int  progress = 0;

                GEDCOMCustomRecord curRecord = null;
                GEDCOMTag          curTag    = null;

                int lineNum = 0;
                while (reader.Peek() != -1)
                {
                    lineNum++;
                    string str = reader.ReadLine();
                    str = GEDCOMUtils.TrimLeft(str);
                    if (str.Length == 0)
                    {
                        continue;
                    }

                    if (!ConvertHelper.IsDigit(str[0]))
                    {
                        FixFTBLine(curRecord, curTag, lineNum, str);
                    }
                    else
                    {
                        int    tagLevel;
                        string tagXRef = "", tagName, tagValue = "";

                        try
                        {
                            var strTok = new StringTokenizer(str);
                            strTok.RecognizeDecimals = false;
                            strTok.IgnoreWhiteSpace  = false;
                            strTok.RecognizeIdents   = true;

                            var token = strTok.Next(); // already trimmed
                            if (token.Kind != TokenKind.Number)
                            {
                                // syntax error
                                throw new EGEDCOMException(string.Format("The string {0} doesn't start with a valid number", str));
                            }
                            tagLevel = (int)token.ValObj;

                            token = strTok.Next();
                            if (token.Kind != TokenKind.WhiteSpace)
                            {
                                // syntax error
                            }

                            token = strTok.Next();
                            if (token.Kind == TokenKind.Symbol && token.Value[0] == '@')
                            {
                                token = strTok.Next();
                                while (token.Kind != TokenKind.Symbol && token.Value[0] != '@')
                                {
                                    tagXRef += token.Value;
                                    token    = strTok.Next();
                                }
                                // FIXME: check for errors
                                //throw new EGEDCOMException(string.Format("The string {0} contains an unterminated XRef pointer", str));
                                //throw new EGEDCOMException(string.Format("The string {0} is expected to start with an XRef pointer", str));

                                token = strTok.Next();
                                strTok.SkipWhiteSpaces();
                            }

                            token = strTok.CurrentToken;
                            if (token.Kind != TokenKind.Word && token.Kind != TokenKind.Ident)
                            {
                                // syntax error
                            }
                            tagName = token.Value.ToUpperInvariant();

                            token = strTok.Next();
                            if (token.Kind == TokenKind.WhiteSpace)
                            {
                                tagValue = strTok.GetRest();
                            }
                        }
                        catch (EGEDCOMException ex)
                        {
                            throw new EGEDCOMException("Syntax error in line " + Convert.ToString(lineNum) + ".\r" + ex.Message);
                        }

                        // convert codepages
                        if (!string.IsNullOrEmpty(tagValue) && fEncodingState == EncodingState.esChanged)
                        {
                            tagValue = ConvertStr(fSourceEncoding, tagValue);
                        }

                        if (tagLevel == 0)
                        {
                            if (curRecord == fTree.Header && fEncodingState == EncodingState.esUnchecked)
                            {
                                // beginning recognition of the first is not header record
                                // to check for additional versions of the code page
                                DefineEncoding(reader);
                            }

                            if (tagName == "INDI")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMIndividualRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "FAM")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMFamilyRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "OBJE")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMMultimediaRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "NOTE")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMNoteRecord(fTree, fTree, "", tagValue));
                            }
                            else if (tagName == "REPO")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMRepositoryRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "SOUR")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMSourceRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "SUBN")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMSubmissionRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "SUBM")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMSubmitterRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "_GROUP")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMGroupRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "_RESEARCH")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMResearchRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "_TASK")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMTaskRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "_COMM")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMCommunicationRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "_LOC")
                            {
                                curRecord = fTree.AddRecord(new GEDCOMLocationRecord(fTree, fTree, "", ""));
                            }
                            else if (tagName == "HEAD")
                            {
                                curRecord = fTree.Header;
                            }
                            else if (tagName == "TRLR")
                            {
                                break;
                            }
                            else
                            {
                                curRecord = null;
                            }

                            if (curRecord != null && tagXRef != "")
                            {
                                curRecord.XRef = tagXRef;
                            }
                            curTag = null;
                        }
                        else
                        {
                            if (curRecord != null)
                            {
                                if (curTag == null || tagLevel == 1)
                                {
                                    curTag = curRecord.AddTag(tagName, tagValue, null);
                                }
                                else
                                {
                                    while (tagLevel <= curTag.Level)
                                    {
                                        curTag = (curTag.Parent as GEDCOMTag);
                                    }
                                    curTag = curTag.AddTag(tagName, tagValue, null);
                                }
                            }
                        }
                    }

                    if (progressHandler != null)
                    {
                        int newProgress = (int)Math.Min(100, (fileStream.Position * 100.0f) / fileSize);

                        if (progress != newProgress)
                        {
                            progress = newProgress;
                            progressHandler(fTree, progress);
                        }
                    }
                }
            }
            finally
            {
                fTree.State = GEDCOMState.osReady;
            }
        }
 internal static void CreateOutlineAction(PdfDictionary outline, Hashtable map, PdfWriter writer, bool namedAsNames)
 {
     try
     {
         string action = (string)map["Action"];
         if ("GoTo".Equals(action))
         {
             string p;
             if ((p = (string)map["Named"]) != null)
             {
                 if (namedAsNames)
                 {
                     outline.Put(PdfName.Dest, new PdfName(p));
                 }
                 else
                 {
                     outline.Put(PdfName.Dest, new PdfString(p, null));
                 }
             }
             else if ((p = (string)map["Page"]) != null)
             {
                 PdfArray        ar = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(p);
                 int             n  = int.Parse(tk.NextToken());
                 ar.Add(writer.GetPageReference(n));
                 if (!tk.HasMoreTokens())
                 {
                     ar.Add(PdfName.Xyz);
                     ar.Add(new float[] { 0, 10000, 0 });
                 }
                 else
                 {
                     string fn = tk.NextToken();
                     if (fn.StartsWith("/"))
                     {
                         fn = fn.Substring(1);
                     }
                     ar.Add(new PdfName(fn));
                     for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k)
                     {
                         fn = tk.NextToken();
                         if (fn.Equals("null"))
                         {
                             ar.Add(PdfNull.Pdfnull);
                         }
                         else
                         {
                             ar.Add(new PdfNumber(fn));
                         }
                     }
                 }
                 outline.Put(PdfName.Dest, ar);
             }
         }
         else if ("GoToR".Equals(action))
         {
             string        p;
             PdfDictionary dic = new PdfDictionary();
             if ((p = (string)map["Named"]) != null)
             {
                 dic.Put(PdfName.D, new PdfString(p, null));
             }
             else if ((p = (string)map["NamedN"]) != null)
             {
                 dic.Put(PdfName.D, new PdfName(p));
             }
             else if ((p = (string)map["Page"]) != null)
             {
                 PdfArray        ar = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(p);
                 ar.Add(new PdfNumber(tk.NextToken()));
                 if (!tk.HasMoreTokens())
                 {
                     ar.Add(PdfName.Xyz);
                     ar.Add(new float[] { 0, 10000, 0 });
                 }
                 else
                 {
                     string fn = tk.NextToken();
                     if (fn.StartsWith("/"))
                     {
                         fn = fn.Substring(1);
                     }
                     ar.Add(new PdfName(fn));
                     for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k)
                     {
                         fn = tk.NextToken();
                         if (fn.Equals("null"))
                         {
                             ar.Add(PdfNull.Pdfnull);
                         }
                         else
                         {
                             ar.Add(new PdfNumber(fn));
                         }
                     }
                 }
                 dic.Put(PdfName.D, ar);
             }
             string file = (string)map["File"];
             if (dic.Size > 0 && file != null)
             {
                 dic.Put(PdfName.S, PdfName.Gotor);
                 dic.Put(PdfName.F, new PdfString(file));
                 string nw = (string)map["NewWindow"];
                 if (nw != null)
                 {
                     if (nw.Equals("true"))
                     {
                         dic.Put(PdfName.Newwindow, PdfBoolean.Pdftrue);
                     }
                     else if (nw.Equals("false"))
                     {
                         dic.Put(PdfName.Newwindow, PdfBoolean.Pdffalse);
                     }
                 }
                 outline.Put(PdfName.A, dic);
             }
         }
         else if ("URI".Equals(action))
         {
             string uri = (string)map["URI"];
             if (uri != null)
             {
                 PdfDictionary dic = new PdfDictionary();
                 dic.Put(PdfName.S, PdfName.Uri);
                 dic.Put(PdfName.Uri, new PdfString(uri));
                 outline.Put(PdfName.A, dic);
             }
         }
         else if ("Launch".Equals(action))
         {
             string file = (string)map["File"];
             if (file != null)
             {
                 PdfDictionary dic = new PdfDictionary();
                 dic.Put(PdfName.S, PdfName.Launch);
                 dic.Put(PdfName.F, new PdfString(file));
                 outline.Put(PdfName.A, dic);
             }
         }
     }
     catch
     {
         // empty on purpose
     }
 }
Exemplo n.º 31
0
        /**
         * Gives you a BaseColor based on a name.
         *
         * @param name
         *            a name such as black, violet, cornflowerblue or #RGB or #RRGGBB
         *            or RGB or RRGGBB or rgb(R,G,B)
         * @return the corresponding BaseColor object.  Never returns null.
         * @throws IllegalArgumentException
         *             if the String isn't a know representation of a color.
         */
        public static BaseColor GetRGBColor(String name)
        {
            int[] c = { 0, 0, 0, 255 };
            name = name.ToLowerInvariant();
            bool colorStrWithoutHash = MissingHashColorFormat(name);

            if (name.StartsWith("#") || colorStrWithoutHash)
            {
                if (!colorStrWithoutHash)
                {
                    name = name.Substring(1); // lop off the # to unify hex parsing.
                }
                if (name.Length == 3)
                {
                    String s = name.Substring(0, 1);
                    c[0] = int.Parse(s + s, NumberStyles.HexNumber);
                    String s2 = name.Substring(1, 1);
                    c[1] = int.Parse(s2 + s2, NumberStyles.HexNumber);
                    String s3 = name.Substring(2);
                    c[2] = int.Parse(s3 + s3, NumberStyles.HexNumber);
                    return(new BaseColor(c[0], c[1], c[2], c[3]));
                }
                if (name.Length == 6)
                {
                    c[0] = int.Parse(name.Substring(0, 2), NumberStyles.HexNumber);
                    c[1] = int.Parse(name.Substring(2, 2), NumberStyles.HexNumber);
                    c[2] = int.Parse(name.Substring(4), NumberStyles.HexNumber);
                    return(new BaseColor(c[0], c[1], c[2], c[3]));
                }
                throw new ArgumentException(MessageLocalization.GetComposedMessage("unknown.color.format.must.be.rgb.or.rrggbb"));
            }
            else if (name.StartsWith("rgb("))
            {
                StringTokenizer tok = new StringTokenizer(name, "rgb(), \t\r\n\f");
                for (int k = 0; k < 3; ++k)
                {
                    String v = tok.NextToken();
                    if (v.EndsWith("%"))
                    {
                        c[k] = int.Parse(v.Substring(0, v.Length - 1)) * 255 / 100;
                    }
                    else
                    {
                        c[k] = int.Parse(v);
                    }
                    if (c[k] < 0)
                    {
                        c[k] = 0;
                    }
                    else if (c[k] > 255)
                    {
                        c[k] = 255;
                    }
                }
                return(new BaseColor(c[0], c[1], c[2], c[3]));
            }
            name = name.ToLower(CultureInfo.InvariantCulture);
            if (!NAMES.ContainsKey(name))
            {
                // TODO localize this error message.
                throw new ArgumentException("Color '" + name + "' not found.");
            }
            c = NAMES[name];
            return(new BaseColor(c[0], c[1], c[2], c[3]));
        }
Exemplo n.º 32
0
        private void showTime(DateTime dateTime)
        {
            // get desktop
            string jpgFile = dataDir + "\\" + dateTime.ToString("yyyy-MM-dd") + "\\desktop-" +
                             dateTime.ToString("HH.mm.ss") + ".1234.jpg";

            backImage = Image.FromFile(jpgFile);

            desktopView.setImage(backImage);
            // pbxScreen.Invalidate();

            shownDate = dateTime;

            // get process list / windows
            // Open the file and read it back.
            List <ProcessDetails> pds = new List <ProcessDetails>();
            List <WindowDetails>  wds = new List <WindowDetails>();
            string datafile           = dataDir + "\\" + dateTime.ToString("yyyy-MM-dd") + "\\windowList.log";

            using (System.IO.StreamReader sr = System.IO.File.OpenText(datafile)) {
                string   s           = "";
                string   country     = sr.ReadLine();
                DateTime parsingDate = new DateTime();
                Boolean  eof         = false;

                while ((!eof) && (s = sr.ReadLine()) != null)
                {
                    // s = s.Trim();
                    if (s.StartsWith("*** Begin snapshot "))
                    {
                        string      d           = s.Substring(19, 8);
                        CultureInfo cultureInfo = CultureInfo.CurrentCulture;
                        parsingDate = DateTime.ParseExact(d, "HH.mm.ss", cultureInfo);
                        parsingDate = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
                                                   parsingDate.Hour, parsingDate.Minute, parsingDate.Second);
                    }
                    else if (s.StartsWith("P + "))
                    {
                        ProcessDetails pd = ProcessDetails.ParseString(s.Substring(4));
                        if (pd != null)
                        {
                            pds.Add(pd);
                        }
                        else
                        {
                            Console.WriteLine("Could not parse P+: " + s);
                        }
                    }
                    else if (s.StartsWith("W + "))
                    {
                        WindowDetails wd = WindowDetails.ParseString(s.Substring(4));
                        if (wd != null)
                        {
                            wds.Add(wd);
                        }
                        else
                        {
                            Console.WriteLine("Could not parse w+: " + s);
                        }
                    }
                    else if (s.StartsWith("WO ! "))
                    {
                        List <int>      newOrder = new List <int>();
                        StringTokenizer st       = new StringTokenizer(s.Substring(5), " ");
                        while (st.HasMoreTokens())
                        {
                            newOrder.Add(Convert.ToInt32(st.NextToken()));
                        }
                    }

                    // read next line
                    s = sr.ReadLine();
                }
            }

            lstProcess.BeginUpdate();
            lstProcess.Items.Clear();
            foreach (WindowDetails wd in wds)
            {
                // @TODO check if window is visible
                Console.WriteLine("Adding wd '" + wd.title + "'");
                ListViewItem lvi = new ListViewItem(new string[] { wd.title }, Convert.ToString(wd.iconId));
                lvi.Text = wd.title;
                lvi.Tag  = wd;
                // lvi.ImageIndex = lstProcess.SmallImageList.Images.IndexOfKey();
                lstProcess.Items.Add(lvi);
            }
            lstProcess.EndUpdate();
        }
Exemplo n.º 33
0
        static AdobeGlyphList()
        {
            Stream resource = null;

            try {
                resource = ResourceUtil.GetResourceStream(FontConstants.RESOURCE_PATH + "AdobeGlyphList.txt");
                if (resource == null)
                {
                    String msg = "AdobeGlyphList.txt not found as resource. (It must exist as resource in the package com.itextpdf.text.pdf.fonts)";
                    throw new Exception(msg);
                }
                byte[]       buf    = new byte[1024];
                MemoryStream stream = new MemoryStream();
                while (true)
                {
                    int size = resource.Read(buf);
                    if (size < 0)
                    {
                        break;
                    }
                    stream.Write(buf, 0, size);
                }
                resource.Close();
                resource = null;
                String          s  = PdfEncodings.ConvertToString(stream.ToArray(), null);
                StringTokenizer tk = new StringTokenizer(s, "\r\n");
                while (tk.HasMoreTokens())
                {
                    String line = tk.NextToken();
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }
                    StringTokenizer t2 = new StringTokenizer(line, " ;\r\n\t\f");
                    if (!t2.HasMoreTokens())
                    {
                        continue;
                    }
                    String name = t2.NextToken();
                    if (!t2.HasMoreTokens())
                    {
                        continue;
                    }
                    String hex = t2.NextToken();
                    // AdobeGlyphList could contains symbols with marks, e.g.:
                    // resh;05E8
                    // reshhatafpatah;05E8 05B2
                    // So in this case we will just skip this nam
                    if (t2.HasMoreTokens())
                    {
                        continue;
                    }
                    int num = System.Convert.ToInt32(hex, 16);
                    unicode2names[num]  = name;
                    names2unicode[name] = num;
                }
            }
            catch (Exception e) {
                System.Console.Error.WriteLine("AdobeGlyphList.txt loading error: " + e.Message);
            }
            finally {
                if (resource != null)
                {
                    try {
                        resource.Close();
                    }
                    catch (Exception) {
                    }
                }
            }
        }
Exemplo n.º 34
0
 public void StringTokenizerConstructorTest2()
 {
     string str = string.Empty; // TODO: Initialize to an appropriate value
     StringTokenizer target = new StringTokenizer(str);
     Assert.IsNotNull(target);
 }
Exemplo n.º 35
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (output is null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            output.TagName = null;

            if (string.IsNullOrEmpty(Include) && string.IsNullOrEmpty(Exclude))
            {
                return;
            }

            var platform = _resolver.Name.ToString();

            if (Exclude != null)
            {
                var tokenizer = new StringTokenizer(Exclude, NameSeparator);
                foreach (var item in tokenizer)
                {
                    var client = item.Trim();
                    if (!client.HasValue || client.Length <= 0)
                    {
                        continue;
                    }

                    if (!client.Equals(platform, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    output.SuppressOutput();
                    return;
                }
            }

            var has = false;

            if (Include != null)
            {
                var tokenizer = new StringTokenizer(Include, NameSeparator);
                foreach (var item in tokenizer)
                {
                    var client = item.Trim();
                    if (client.HasValue && client.Length > 0)
                    {
                        has = true;
                        if (client.Equals(platform, StringComparison.OrdinalIgnoreCase))
                        {
                            return;
                        }
                    }
                }
            }

            if (has)
            {
                output.SuppressOutput();
            }
        }
Exemplo n.º 36
0
        static GlyphList()
        {
            Stream istr = null;

            try {
                istr = BaseFont.GetResourceStream(BaseFont.RESOURCE_PATH + "glyphlist.txt");
                if (istr == null)
                {
                    String msg = "glyphlist.txt not found as resource.";
                    throw new Exception(msg);
                }
                byte[]       buf  = new byte[1024];
                MemoryStream outp = new MemoryStream();
                while (true)
                {
                    int size = istr.Read(buf, 0, buf.Length);
                    if (size == 0)
                    {
                        break;
                    }
                    outp.Write(buf, 0, size);
                }
                istr.Close();
                istr = null;
                String          s  = PdfEncodings.ConvertToString(outp.ToArray(), null);
                StringTokenizer tk = new StringTokenizer(s, "\r\n");
                while (tk.HasMoreTokens())
                {
                    String line = tk.NextToken();
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }
                    StringTokenizer t2   = new StringTokenizer(line, " ;\r\n\t\f");
                    String          name = null;
                    String          hex  = null;
                    if (!t2.HasMoreTokens())
                    {
                        continue;
                    }
                    name = t2.NextToken();
                    if (!t2.HasMoreTokens())
                    {
                        continue;
                    }
                    hex = t2.NextToken();
                    int num = int.Parse(hex, NumberStyles.HexNumber);
                    unicode2names[num]  = name;
                    names2unicode[name] = new int[] { num };
                }
            }
            catch (Exception e) {
                Console.Error.WriteLine("glyphlist.txt loading error: " + e.Message);
            }
            finally {
                if (istr != null)
                {
                    try {
                        istr.Close();
                    }
                    catch {
                        // empty on purpose
                    }
                }
            }
        }
Exemplo n.º 37
0
        /// <summary> Reads the tag set file, and initializes the object.</summary>
        /// <param name="filePath">- the file for morpheme tag set
        /// </param>
        /// <throws>  IOException </throws>
        public virtual void  init(System.String filePath, int tagSetFlag)
        {
            System.IO.StreamReader br = new System.IO.StreamReader(
                new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read),
                System.Text.Encoding.UTF8);
            System.String line = null;

            title     = "";
            version   = "";
            copyright = "";
            author    = "";
            date      = "";
            editor    = "";
            tagList.Clear();
            irregularList.Clear();
            tagSetMap.Clear();

            List <int> tempTagNumbers = new List <int>();

            while ((line = br.ReadLine()) != null)
            {
                StringTokenizer lineTokenizer = new StringTokenizer(line, "\t");

                if (lineTokenizer.HasMoreTokens == false)
                {
                    continue;
                }
                System.String lineToken = lineTokenizer.NextToken;

                if (lineToken.StartsWith("@"))
                {
                    if ("@title".Equals(lineToken))
                    {
                        title = lineTokenizer.NextToken;
                    }
                    else if ("@version".Equals(lineToken))
                    {
                        version = lineTokenizer.NextToken;
                    }
                    else if ("@copyright".Equals(lineToken))
                    {
                        copyright = lineTokenizer.NextToken;
                    }
                    else if ("@author".Equals(lineToken))
                    {
                        author = lineTokenizer.NextToken;
                    }
                    else if ("@date".Equals(lineToken))
                    {
                        date = lineTokenizer.NextToken;
                    }
                    else if ("@editor".Equals(lineToken))
                    {
                        editor = lineTokenizer.NextToken;
                    }
                }
                else if ("TAG".Equals(lineToken))
                {
                    tagList.Add(lineTokenizer.NextToken);
                }
                else if ("TSET".Equals(lineToken))
                {
                    System.String   tagSetName   = lineTokenizer.NextToken;
                    StringTokenizer tagTokenizer = new StringTokenizer(lineTokenizer.NextToken, " ");

                    while (tagTokenizer.HasMoreTokens)
                    {
                        System.String tagToken  = tagTokenizer.NextToken;
                        int           tagNumber = tagList.IndexOf(tagToken);

                        if (tagNumber != -1)
                        {
                            tempTagNumbers.Add(tagNumber);
                        }
                        else
                        {
                            int[] values = tagSetMap[tagToken];
                            if (values != null)
                            {
                                for (int i = 0; i < values.Length; i++)
                                {
                                    tempTagNumbers.Add(values[i]);
                                }
                            }
                        }
                    }
                    int[] tagNumbers = new int[tempTagNumbers.Count];

                    IEnumerator <int> iter = tempTagNumbers.GetEnumerator();
                    for (int i = 0; iter.MoveNext(); i++)
                    {
                        tagNumbers[i] = iter.Current;
                    }
                    tagSetMap[tagSetName] = tagNumbers;
                    tempTagNumbers.Clear();
                }
                else if ("IRR".Equals(lineToken))
                {
                    irregularList.Add(lineTokenizer.NextToken);
                }
            }
            br.Close();

            TagTypes  = tagSetFlag;
            indexTags = tagSetMap["index"];
            unkTags   = tagSetMap["unkset"];
            iwgTag    = tagList.IndexOf("iwg");
            unkTag    = tagList.IndexOf("unk");
            numTag    = tagList.IndexOf("nnc");

            IRR_TYPE_B   = getIrregularID("irrb");
            IRR_TYPE_S   = getIrregularID("irrs");
            IRR_TYPE_D   = getIrregularID("irrd");
            IRR_TYPE_H   = getIrregularID("irrh");
            IRR_TYPE_REU = getIrregularID("irrlu");
            IRR_TYPE_REO = getIrregularID("irrle");
        }
Exemplo n.º 38
0
        /** Reads the font metrics
         * @param rf the AFM file
         * @throws DocumentException the AFM file is invalid
         * @throws IOException the AFM file could not be read
         */
        public void Process(RandomAccessFileOrArray rf)
        {
            string line;
            bool   isMetrics = false;

            while ((line = rf.ReadLine()) != null)
            {
                StringTokenizer tok = new StringTokenizer(line, " ,\n\r\t\f");
                if (!tok.HasMoreTokens())
                {
                    continue;
                }
                string ident = tok.NextToken();
                if (ident.Equals("FontName"))
                {
                    FontName = tok.NextToken("\u00ff").Substring(1);
                }
                else if (ident.Equals("FullName"))
                {
                    FullName = tok.NextToken("\u00ff").Substring(1);
                }
                else if (ident.Equals("FamilyName"))
                {
                    FamilyName = tok.NextToken("\u00ff").Substring(1);
                }
                else if (ident.Equals("Weight"))
                {
                    Weight = tok.NextToken("\u00ff").Substring(1);
                }
                else if (ident.Equals("ItalicAngle"))
                {
                    ItalicAngle = float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("IsFixedPitch"))
                {
                    IsFixedPitch = tok.NextToken().Equals("true");
                }
                else if (ident.Equals("CharacterSet"))
                {
                    CharacterSet = tok.NextToken("\u00ff").Substring(1);
                }
                else if (ident.Equals("FontBBox"))
                {
                    llx = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    lly = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    urx = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    ury = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("UnderlinePosition"))
                {
                    UnderlinePosition = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("UnderlineThickness"))
                {
                    UnderlineThickness = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("EncodingScheme"))
                {
                    EncodingScheme = tok.NextToken("\u00ff").Substring(1);
                }
                else if (ident.Equals("CapHeight"))
                {
                    CapHeight = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("XHeight"))
                {
                    XHeight = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("Ascender"))
                {
                    Ascender = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("Descender"))
                {
                    Descender = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("StdHW"))
                {
                    StdHW = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("StdVW"))
                {
                    StdVW = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("StartCharMetrics"))
                {
                    isMetrics = true;
                    break;
                }
            }
            if (!isMetrics)
            {
                throw new DocumentException(MessageLocalization.GetComposedMessage("missing.startcharmetrics.in.1", fileName));
            }
            while ((line = rf.ReadLine()) != null)
            {
                StringTokenizer tok = new StringTokenizer(line);
                if (!tok.HasMoreTokens())
                {
                    continue;
                }
                string ident = tok.NextToken();
                if (ident.Equals("EndCharMetrics"))
                {
                    isMetrics = false;
                    break;
                }
                int    C  = -1;
                int    WX = 250;
                string N  = "";
                int[]  B  = null;

                tok = new StringTokenizer(line, ";");
                while (tok.HasMoreTokens())
                {
                    StringTokenizer tokc = new StringTokenizer(tok.NextToken());
                    if (!tokc.HasMoreTokens())
                    {
                        continue;
                    }
                    ident = tokc.NextToken();
                    if (ident.Equals("C"))
                    {
                        C = int.Parse(tokc.NextToken());
                    }
                    else if (ident.Equals("WX"))
                    {
                        WX = (int)float.Parse(tokc.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    }
                    else if (ident.Equals("N"))
                    {
                        N = tokc.NextToken();
                    }
                    else if (ident.Equals("B"))
                    {
                        B = new int[] { int.Parse(tokc.NextToken()),
                                        int.Parse(tokc.NextToken()),
                                        int.Parse(tokc.NextToken()),
                                        int.Parse(tokc.NextToken()) };
                    }
                }
                Object[] metrics = new Object[] { C, WX, N, B };
                if (C >= 0)
                {
                    CharMetrics[C] = metrics;
                }
                CharMetrics[N] = metrics;
            }
            if (isMetrics)
            {
                throw new DocumentException(MessageLocalization.GetComposedMessage("missing.endcharmetrics.in.1", fileName));
            }
            if (!CharMetrics.ContainsKey("nonbreakingspace"))
            {
                Object[] space;
                CharMetrics.TryGetValue("space", out space);
                if (space != null)
                {
                    CharMetrics["nonbreakingspace"] = space;
                }
            }
            while ((line = rf.ReadLine()) != null)
            {
                StringTokenizer tok = new StringTokenizer(line);
                if (!tok.HasMoreTokens())
                {
                    continue;
                }
                string ident = tok.NextToken();
                if (ident.Equals("EndFontMetrics"))
                {
                    return;
                }
                if (ident.Equals("StartKernPairs"))
                {
                    isMetrics = true;
                    break;
                }
            }
            if (!isMetrics)
            {
                throw new DocumentException(MessageLocalization.GetComposedMessage("missing.endfontmetrics.in.1", fileName));
            }
            while ((line = rf.ReadLine()) != null)
            {
                StringTokenizer tok = new StringTokenizer(line);
                if (!tok.HasMoreTokens())
                {
                    continue;
                }
                string ident = tok.NextToken();
                if (ident.Equals("KPX"))
                {
                    string   first  = tok.NextToken();
                    string   second = tok.NextToken();
                    int      width  = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    Object[] relates;
                    KernPairs.TryGetValue(first, out relates);
                    if (relates == null)
                    {
                        KernPairs[first] = new Object[] { second, width }
                    }
                    ;
                    else
                    {
                        int      n        = relates.Length;
                        Object[] relates2 = new Object[n + 2];
                        Array.Copy(relates, 0, relates2, 0, n);
                        relates2[n]      = second;
                        relates2[n + 1]  = width;
                        KernPairs[first] = relates2;
                    }
                }
                else if (ident.Equals("EndKernPairs"))
                {
                    isMetrics = false;
                    break;
                }
            }
            if (isMetrics)
            {
                throw new DocumentException(MessageLocalization.GetComposedMessage("missing.endkernpairs.in.1", fileName));
            }
            rf.Close();
        }
        /// <summary>The main method, which is essentially the same as in CRFClassifier.</summary>
        /// <remarks>The main method, which is essentially the same as in CRFClassifier. See the class documentation.</remarks>
        /// <exception cref="System.Exception"/>
        public static void Main(string[] args)
        {
            StringUtils.LogInvocationString(log, args);
            Properties props = StringUtils.ArgsToProperties(args);
            CRFBiasedClassifier <CoreLabel> crf = new CRFBiasedClassifier <CoreLabel>(props);
            string testFile = crf.flags.testFile;
            string loadPath = crf.flags.loadClassifier;

            if (loadPath != null)
            {
                crf.LoadClassifierNoExceptions(loadPath, props);
            }
            else
            {
                if (crf.flags.loadJarClassifier != null)
                {
                    // legacy support of old option
                    crf.LoadClassifierNoExceptions(crf.flags.loadJarClassifier, props);
                }
                else
                {
                    crf.LoadDefaultClassifier();
                }
            }
            if (crf.flags.classBias != null)
            {
                StringTokenizer biases = new StringTokenizer(crf.flags.classBias, ",");
                while (biases.HasMoreTokens())
                {
                    StringTokenizer bias  = new StringTokenizer(biases.NextToken(), ":");
                    string          cname = bias.NextToken();
                    double          w     = double.ParseDouble(bias.NextToken());
                    crf.SetBiasWeight(cname, w);
                    log.Info("Setting bias for class " + cname + " to " + w);
                }
            }
            if (testFile != null)
            {
                IDocumentReaderAndWriter <CoreLabel> readerAndWriter = crf.MakeReaderAndWriter();
                if (crf.flags.printFirstOrderProbs)
                {
                    crf.PrintFirstOrderProbs(testFile, readerAndWriter);
                }
                else
                {
                    if (crf.flags.printProbs)
                    {
                        crf.PrintProbs(testFile, readerAndWriter);
                    }
                    else
                    {
                        if (crf.flags.useKBest)
                        {
                            int k = crf.flags.kBest;
                            crf.ClassifyAndWriteAnswersKBest(testFile, k, readerAndWriter);
                        }
                        else
                        {
                            crf.ClassifyAndWriteAnswers(testFile, readerAndWriter, true);
                        }
                    }
                }
            }
        }
Exemplo n.º 40
0
        /// <summary>
        /// Get First/Last Name
        /// </summary>
        /// <param name="name">name</param>
        /// <param name="getFirst">if true first name is returned</param>
        /// <returns>first/last name</returns>
        private String GetName(String name, bool getFirst)
        {
            if (name == null || name.Length == 0)
            {
                return("");
            }
            String first = null;
            String last  = null;

            //	double names not handled gracefully nor titles
            //	nor (former) aristrocratic world de/la/von
            bool            lastFirst = name.IndexOf(',') != -1;
            StringTokenizer st        = null;

            if (lastFirst)
            {
                st = new StringTokenizer(name, ",");
            }
            else
            {
                st = new StringTokenizer(name, " ");
            }
            while (st.HasMoreTokens())
            {
                String s = st.NextToken().Trim();
                if (lastFirst)
                {
                    if (last == null)
                    {
                        last = s;
                    }
                    else if (first == null)
                    {
                        first = s;
                    }
                }
                else
                {
                    if (first == null)
                    {
                        first = s;
                    }
                    else
                    {
                        last = s;
                    }
                }
            }
            if (getFirst)
            {
                if (first == null)
                {
                    return("");
                }
                return(first.Trim());
            }
            if (last == null)
            {
                return("");
            }
            return(last.Trim());
        }
Exemplo n.º 41
0
 public void nextElementTest()
 {
     string str = "next"; // TODO: Initialize to an appropriate value
     StringTokenizer target = new StringTokenizer(str); // TODO: Initialize to an appropriate value
     object expected = str; // TODO: Initialize to an appropriate value
     object actual;
     actual = target.nextElement();
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 42
0
        /// <summary> Reads the impossible connection rules from the specified file.</summary>
        /// <param name="filePath">- the file for the impossible connection rules
        /// </param>
        /// <param name="tagSet">- the morpheme tag set used in the rules
        /// </param>
        /// <throws>  IOException </throws>
        private void readFile(System.String filePath, TagSet tagSet)
        {
            System.IO.StreamReader br = new System.IO.StreamReader(
                new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read), System.Text.Encoding.UTF8);
            System.String line = null;

            List< String > ruleList = new List< String >();

            title = "";
            version = "";
            copyright = "";
            author = "";
            date = "";
            editor = "";
            startTag = "";
            ruleCount = 0;

            while ((line = br.ReadLine()) != null)
            {
                StringTokenizer lineTokenizer = new StringTokenizer(line, "\t");
                if (lineTokenizer.HasMoreTokens == false)
                {
                    continue;
                }

                System.String lineToken = lineTokenizer.NextToken;

                if (lineToken.StartsWith("@"))
                {
                    if ("@title".Equals(lineToken))
                    {
                        title = lineTokenizer.NextToken;
                    }
                    else if ("@version".Equals(lineToken))
                    {
                        version = lineTokenizer.NextToken;
                    }
                    else if ("@copyright".Equals(lineToken))
                    {
                        copyright = lineTokenizer.NextToken;
                    }
                    else if ("@author".Equals(lineToken))
                    {
                        author = lineTokenizer.NextToken;
                    }
                    else if ("@date".Equals(lineToken))
                    {
                        date = lineTokenizer.NextToken;
                    }
                    else if ("@editor".Equals(lineToken))
                    {
                        editor = lineTokenizer.NextToken;
                    }
                }
                else if ("CONNECTION_NOT".Equals(lineToken))
                {
                    ruleList.Add(lineTokenizer.NextToken);
                }
            }

            ruleCount = ruleList.Count;

            notTagTable = new int[ruleCount][];
            for (int i = 0; i < ruleCount; i++)
            {
                notTagTable[i] = new int[2];
            }
            notMorphTable = new System.String[ruleCount][];
            for (int i2 = 0; i2 < ruleCount; i2++)
            {
                notMorphTable[i2] = new System.String[2];
            }

            IEnumerator<string> iter = ruleList.GetEnumerator();
            for (int i = 0; iter.MoveNext(); i++)
            {
                System.String rule = iter.Current;
                StringTokenizer st = new StringTokenizer(rule, " ");
                notMorphTable[i][0] = st.NextToken;
                notTagTable[i][0] = tagSet.getTagID(st.NextToken);
                notMorphTable[i][1] = st.NextToken;
                notTagTable[i][1] = tagSet.getTagID(st.NextToken);
            }

            ruleList.Clear();
            br.Close();
        }
		/// <summary>
		/// Parse inline parameter with syntax as
		/// #propertyName,type=string,dbype=Varchar,direction=Input,nullValue=N/A,handler=string#
		/// </summary>
		/// <param name="token"></param>
		/// <param name="parameterClassType"></param>
		/// <param name="scope"></param>
		/// <returns></returns>
		private ParameterProperty NewParseMapping(string token, Type parameterClassType, IScope scope) 
		{
			ParameterProperty mapping = null;

            string propertyName = string.Empty;
            string type = string.Empty;
            string dbType = string.Empty;
            string direction = string.Empty;
            string callBack = string.Empty;
            string nullValue = string.Empty;

			StringTokenizer paramParser = new StringTokenizer(token, "=,", false);
			IEnumerator enumeratorParam = paramParser.GetEnumerator();
			enumeratorParam.MoveNext();

            propertyName = ((string)enumeratorParam.Current).Trim();

			while (enumeratorParam.MoveNext()) 
			{
				string field = (string)enumeratorParam.Current;
				if (enumeratorParam.MoveNext()) 
				{
					string value = (string)enumeratorParam.Current;
					if ("type".Equals(field)) 
					{
                        type = value;
					} 
					else if ("dbType".Equals(field)) 
					{
                        dbType = value;
					} 
					else if ("direction".Equals(field)) 
					{
                        direction = value;
					} 
					else if ("nullValue".Equals(field)) 
					{
                        nullValue = value;
					} 
					else if ("handler".Equals(field)) 
					{
                        callBack = value;
					} 
					else 
					{
						throw new DataMapperException("Unrecognized parameter mapping field: '" + field + "' in " + token);
					}
				} 
				else 
				{
					throw new DataMapperException("Incorrect inline parameter map format (missmatched name=value pairs): " + token);
				}
			}

            //if (mapping.CallBackName.Length >0)
            //{
            //    mapping.Initialize( scope, parameterClassType );
            //}
            //else
            //{
            //    ITypeHandler handler = null;
            //    if (parameterClassType == null) 
            //    {
            //        handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
            //    } 
            //    else 
            //    {
            //        handler = ResolveTypeHandler( scope.DataExchangeFactory.TypeHandlerFactory, 
            //            parameterClassType, mapping.PropertyName,  
            //            mapping.CLRType, mapping.DbType );
            //    }
            //    mapping.TypeHandler = handler;
            //    mapping.Initialize(  scope, parameterClassType );				
            //}

            return new ParameterProperty(
                propertyName,
                string.Empty,
                callBack,
                type,
                dbType,
                direction,
                nullValue,
                0,
                0,
                -1,
                parameterClassType,
                scope.DataExchangeFactory);
		}
Exemplo n.º 44
0
		/// <summary>
		///  Returns the type that the get expects to receive as a parameter when
		///  setting a member value.
		/// </summary>
		/// <param name="type">The type to check</param>
		/// <param name="memberName">The name of the member</param>
		/// <returns>The type of the member</returns>
		public static Type GetMemberTypeForGetter(Type type, string memberName) 
		{
			if (memberName.IndexOf('.') > -1) 
			{
				StringTokenizer parser = new StringTokenizer(memberName, ".");
				IEnumerator enumerator = parser.GetEnumerator();

				while (enumerator.MoveNext()) 
				{
					memberName = (string)enumerator.Current;
					type = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
				}
			} 
			else 
			{
				type = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
			}

			return type;
		}
		/// <summary>
		/// Parse Inline ParameterMap
		/// </summary>
		/// <param name="statement"></param>
		/// <param name="sqlStatement"></param>
		/// <returns>A new sql command text.</returns>
		/// <param name="scope"></param>
		public SqlText ParseInlineParameterMap(IScope scope, IStatement statement, string sqlStatement)
		{
			string newSql = sqlStatement;
			ArrayList mappingList = new ArrayList();
			Type parameterClassType = null;

			if (statement != null)
			{
				parameterClassType = statement.ParameterClass;
			}

			StringTokenizer parser = new StringTokenizer(sqlStatement, PARAMETER_TOKEN, true);
			StringBuilder newSqlBuffer = new StringBuilder();

			string token = null;
			string lastToken = null;

			IEnumerator enumerator = parser.GetEnumerator();

			while (enumerator.MoveNext()) 
			{
				token = (string)enumerator.Current;

				if (PARAMETER_TOKEN.Equals(lastToken)) 
				{
					if (PARAMETER_TOKEN.Equals(token)) 
					{
						newSqlBuffer.Append(PARAMETER_TOKEN);
						token = null;
					} 
					else 
					{
						ParameterProperty mapping = null; 
						if (token.IndexOf(PARAM_DELIM) > -1) 
						{
							mapping =  OldParseMapping(token, parameterClassType, scope);
						} 
						else 
						{
							mapping = NewParseMapping(token, parameterClassType, scope);
						}															 

						mappingList.Add(mapping);
						newSqlBuffer.Append("? ");

						enumerator.MoveNext();
						token = (string)enumerator.Current;
						if (!PARAMETER_TOKEN.Equals(token)) 
						{
							throw new DataMapperException("Unterminated inline parameter in mapped statement (" + statement.Id + ").");
						}
						token = null;
					}
				} 
				else 
				{
					if (!PARAMETER_TOKEN.Equals(token)) 
					{
						newSqlBuffer.Append(token);
					}
				}

				lastToken = token;
			}

			newSql = newSqlBuffer.ToString();

			ParameterProperty[] mappingArray = (ParameterProperty[]) mappingList.ToArray(typeof(ParameterProperty));

			SqlText sqlText = new SqlText();
			sqlText.Text = newSql;
			sqlText.Parameters = mappingArray;

			return sqlText;
		}
Exemplo n.º 46
0
        /// <summary>
        /// Return the specified member on an object. 
        /// </summary>
        /// <param name="obj">The Object on which to invoke the specified property.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
        /// <returns>An Object representing the return value of the invoked property.</returns>
		public static object GetMemberValue(object obj, string memberName,
            AccessorFactory accessorFactory)
        {
            if (memberName.IndexOf('.') > -1) 
			{
				StringTokenizer parser = new StringTokenizer(memberName, ".");
				IEnumerator enumerator = parser.GetEnumerator();
				object value = obj;

			    while (enumerator.MoveNext()) 
				{
					string token = (string)enumerator.Current;
                    value = GetMember(value, token, accessorFactory);

					if (value == null) 
					{
						break;
					}
				}
				return value;
			}
            return GetMember(obj, memberName, accessorFactory);
        }
Exemplo n.º 47
0
		/// <summary>
		/// Checks to see if the Object have a property/field be a given name.
		/// </summary>
		/// <param name="obj">The Object on which to invoke the specified property.</param>
		/// <param name="propertyName">The name of the property to check for.</param>
		/// <returns>
		/// True or false if the property exists and is readable.
		/// </returns>
		public static bool HasReadableProperty(object obj, string propertyName) 
		{
			bool hasProperty = false;

			if (obj is IDictionary) 
			{
				hasProperty = ((IDictionary) obj).Contains(propertyName);
			} 
			else 
			{
				if (propertyName.IndexOf('.') > -1) 
				{
					StringTokenizer parser = new StringTokenizer(propertyName, ".");
					IEnumerator enumerator = parser.GetEnumerator();
					Type type = obj.GetType();

					while (enumerator.MoveNext()) 
					{ 
						propertyName = (string)enumerator.Current;
						type = ReflectionInfo.GetInstance(type).GetGetterType(propertyName);
						hasProperty = ReflectionInfo.GetInstance(type).HasReadableMember(propertyName);
					}
				} 
				else 
				{
					hasProperty = ReflectionInfo.GetInstance(obj.GetType()).HasReadableMember(propertyName);
				}
			}
			
			return hasProperty;
		}
Exemplo n.º 48
0
        /// <summary>
        /// Appends the specified search text to the current expression.
        /// </summary>
        /// <param name="searchText">The search text to append.</param>
        protected void ParseCore(String searchText)
        {
            IList<String> quotedValues = new List<String>();

            int leftNumber = 0;
            int rightNumber = 0;
            int i = -1;

            // last param was a key word
            bool isKeyWord = false;

            // used to track if the first param is a key word
            // i.e., and or "john smith"
            int numParams = 0;

            // use AND to search all
            // i.e. John Smith would become John and Smith
            // however "John Smith" is one entity
            bool needToInsertAND = false;

            String outStr = ParseQuotes(searchText, quotedValues);
            StringTokenizer tokenizer = new StringTokenizer(outStr, "( ),\t\r\n", true);
            String nextToken;

            while ( tokenizer.HasMoreTokens )
            {
                // trim token
                nextToken = tokenizer.NextToken.Trim();

                // left parenthesis
                if ( nextToken.Equals(SqlUtil.LEFT) )
                {
                    leftNumber++;

                    if ( needToInsertAND )
                    {
                        AppendAnd();
                    }

                    OpenGrouping();

                    needToInsertAND = false;
                    isKeyWord = false;
                }

                // right parenthesis
                else if ( nextToken.Equals(SqlUtil.RIGHT) )
                {
                    rightNumber++;

                    CloseGrouping();

                    needToInsertAND = true;
                    isKeyWord = false;
                }
                // comma
                else if ( nextToken.Equals(SqlUtil.COMMA) )
                {
                    AppendOr();
                    needToInsertAND = false;
                    isKeyWord = false;
                }
                // token is a key word (such as AND, OR,...)
                else if ( IsKeyWord(nextToken) )
                {
                    numParams++;

                    // if this is the first parameter in the entire string
                    // treat it as a regular param (not a key word)
                    if ( numParams == 1 )
                    {
                        needToInsertAND = true;

                        AppendSearchText(nextToken);
                    }

                    // if only two params
                    else if ( ( numParams == 2 ) && ( tokenizer.CountTokens <= 1 ) )
                    {
                        AppendAnd();
                        AppendSearchText(nextToken);
                    }

                    // if the last string was a key word
                    else if ( isKeyWord )
                    {
                        needToInsertAND = true;

                        // treat this param as a regular string, not a key word
                        isKeyWord = false;

                        AppendSearchText(nextToken);
                    }
                    else
                    {
                        // make sure this is not the last param, if so use AND to search all
                        if ( tokenizer.CountTokens <= 1 )
                        {
                            AppendAnd();
                            AppendSearchText(nextToken);
                        }
                        else
                        {
                            if ( SqlUtil.AND.Equals(nextToken, StringComparison.OrdinalIgnoreCase) )
                            {
                                AppendAnd();
                            }
                            else if ( SqlUtil.OR.Equals(nextToken, StringComparison.OrdinalIgnoreCase) )
                            {
                                AppendOr();
                            }

                            needToInsertAND = false;
                            isKeyWord = true;
                        }
                    }
                }
                else if ( nextToken.Equals(" ") )
                {
                    AppendSpace();
                }
                else if ( nextToken.Equals("") )
                {
                }
                // string in quotes
                else if ( nextToken.Equals(SqlUtil.TOKEN) )
                {
                    numParams++;

                    if ( needToInsertAND )
                    {
                        AppendAnd();
                    }

                    needToInsertAND = true;

                    // if the search param string is like: "John Smith" and Jones
                    // the and needs to be translated to a SQL "AND"
                    isKeyWord = false;

                    // get the next quoted string
                    i++;

                    AppendSearchText(quotedValues[i]);
                }
                // a regular string other than the above cases
                else
                {
                    numParams++;

                    if ( needToInsertAND )
                    {
                        AppendAnd();
                    }

                    needToInsertAND = true;
                    isKeyWord = false;

                    AppendSearchText(nextToken);
                }
            }

            if ( leftNumber != rightNumber )
            {
                throw new ArgumentException("Syntax Error: mismatched parenthesis.");
            }
        }
    public void OnTextSubtitle(ref TEXT_SUBTITLE sub)
    {
      try
      {
        if (sub.page == _activeSubPage)
        {
          Log.Debug("Page: " + sub.page);
          Log.Debug("Character table: " + sub.encoding);
          Log.Debug("Timeout: " + sub.timeOut);
          Log.Debug("Timestamp: " + sub.timeStamp);
          Log.Debug("Language: " + sub.language);

          String content = sub.text;
          if (content == null)
          {
            Log.Error("OnTextSubtitle: sub.txt == null!");
            return;
          }
          Log.Debug("Content: ");
          if (content.Trim().Length > 0) // debug log subtitles
          {
            StringTokenizer st = new StringTokenizer(content, new char[] {'\n'});
            while (st.HasMore)
            {
              Log.Debug(st.NextToken());
            }
          }
          else
          {
            Log.Debug("Page: <BLANK PAGE>");
          }
        }
      }
      catch (Exception e)
      {
        Log.Error("Problem with TEXT_SUBTITLE");
        Log.Error(e);
      }

      try
      {
        // if we dont need the subtitle
        if (!_renderSubtitles || _useBitmap || (_activeSubPage != sub.page))
        {
          //
          //chemelli: too much logging. You can check if logs have:
          //          Log.Debug("Page: " + sub.page);  or Log.Debug("Page: <BLANK PAGE>");
          //          and
          //          Log.Debug("Text subtitle (page {0}) ACCEPTED: [...]
          //          to know the evaluation of this if block
          //
          //Log.Debug("Text subtitle (page {0}) discarded: useBitmap is {1} and activeSubPage is {2}", sub.page, useBitmap,
          //          activeSubPage);

          return;
        }
        Log.Debug("Text subtitle (page {0}) ACCEPTED: useBitmap is {1} and activeSubPage is {2}", sub.page, _useBitmap,
                  _activeSubPage);

        Subtitle subtitle = new Subtitle();

        // TODO - RenderText should directly draw to a D3D texture
        subtitle.subBitmap = RenderText(sub.lc);
        subtitle.timeOut = sub.timeOut;
        subtitle.presentTime = sub.timeStamp / 90000.0f + _startPos;

        subtitle.height = 576;
        subtitle.width = 720;
        subtitle.screenHeight = 576;
        subtitle.screenWidth = 720;
        subtitle.firstScanLine = 0;

        Texture texture = null;
        try
        {
          // allocate new texture
          texture = new Texture(GUIGraphicsContext.DX9Device, subtitle.subBitmap.Width,
                                subtitle.subBitmap.Height, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
          int pitch;
          using (GraphicsStream a = texture.LockRectangle(0, LockFlags.Discard, out pitch))
          {
            BitmapData bd = subtitle.subBitmap.LockBits(new Rectangle(0, 0, subtitle.subBitmap.Width,
                                                                      subtitle.subBitmap.Height), ImageLockMode.ReadOnly,
                                                        PixelFormat.Format32bppArgb);

            // Quick copy of content
            unsafe
            {
              byte* to = (byte*)a.InternalDataPointer;
              byte* from = (byte*)bd.Scan0.ToPointer();
              for (int y = 0; y < bd.Height; ++y)
              {
                for (int x = 0; x < bd.Width * 4; ++x)
                {
                  to[pitch * y + x] = from[y * bd.Stride + x];
                }
              }
            }

            texture.UnlockRectangle(0);
            subtitle.subBitmap.UnlockBits(bd);
            subtitle.subBitmap.SafeDispose();
            subtitle.subBitmap = null;
            subtitle.texture = texture;
            a.Close();
          }
        }
        catch (Exception e)
        {
          Log.Debug("SubtitleRenderer: Failed to create subtitle surface!");
          Log.Error(e);
          return;
        }

        AddSubtitle(subtitle);
      }
      catch (Exception e)
      {
        Log.Error("Problem processing text subtitle");
        Log.Error(e);
      }
    }
Exemplo n.º 50
0
        /**
         * Creates a Font object based on a chain of properties.
         * @param   chain   chain of properties
         * @return  an iText Font object
         */
        public Font GetFont(ChainedProperties chain)
        {
            // [1] font name

            String face = chain[HtmlTags.FACE];

            // try again, under the CSS key.
            //ISSUE: If both are present, we always go with face, even if font-family was
            //  defined more recently in our ChainedProperties.  One solution would go like this:
            //    Map all our supported style attributes to the 'normal' tag name, so we could
            //    look everything up under that one tag, retrieving the most current value.
            if (face == null || face.Trim().Length == 0)
            {
                face = chain[HtmlTags.FONTFAMILY];
            }
            // if the font consists of a comma separated list,
            // take the first font that is registered
            if (face != null)
            {
                StringTokenizer tok = new StringTokenizer(face, ",");
                while (tok.HasMoreTokens())
                {
                    face = tok.NextToken().Trim();
                    if (face.StartsWith("\""))
                    {
                        face = face.Substring(1);
                    }
                    if (face.EndsWith("\""))
                    {
                        face = face.Substring(0, face.Length - 1);
                    }
                    if (provider.IsRegistered(face))
                    {
                        break;
                    }
                }
            }

            // [2] encoding
            String encoding = chain[HtmlTags.ENCODING];

            if (encoding == null)
            {
                encoding = BaseFont.WINANSI;
            }

            // [3] embedded

            // [4] font size
            String value = chain[HtmlTags.SIZE];
            float  size  = 12;

            if (value != null)
            {
                size = float.Parse(value, CultureInfo.InvariantCulture);
            }

            // [5] font style
            int style = 0;

            // text-decoration
            String decoration = chain[HtmlTags.TEXTDECORATION];

            if (decoration != null && decoration.Trim().Length != 0)
            {
                if (HtmlTags.UNDERLINE.Equals(decoration))
                {
                    style |= Font.UNDERLINE;
                }
                else if (HtmlTags.LINETHROUGH.Equals(decoration))
                {
                    style |= Font.STRIKETHRU;
                }
            }
            // italic
            if (chain.HasProperty(HtmlTags.I))
            {
                style |= Font.ITALIC;
            }
            // bold
            if (chain.HasProperty(HtmlTags.B))
            {
                style |= Font.BOLD;
            }
            // underline
            if (chain.HasProperty(HtmlTags.U))
            {
                style |= Font.UNDERLINE;
            }
            // strikethru
            if (chain.HasProperty(HtmlTags.S))
            {
                style |= Font.STRIKETHRU;
            }

            // [6] Color
            BaseColor color = HtmlUtilities.DecodeColor(chain[HtmlTags.COLOR]);

            // Get the font object from the provider
            return(provider.GetFont(face, encoding, true, size, style, color));
        }
Exemplo n.º 51
0
		/// <summary>
		///  Returns the type that the get expects to receive as a parameter when
		///  setting a member value.
		/// </summary>
		/// <param name="obj">The object to check</param>
		/// <param name="memberName">The name of the member</param>
		/// <returns>The type of the member</returns>
		public static Type GetMemberTypeForGetter(object obj, string memberName) 
		{
			Type type = obj.GetType();

			if (obj is IDictionary) 
			{
				IDictionary map = (IDictionary) obj;
				object value = map[memberName];
				if (value == null) 
				{
					type = typeof(object);
				} 
				else 
				{
					type = value.GetType();
				}
			} 
			else 
			{
				if (memberName.IndexOf('.') > -1) 
				{
					StringTokenizer parser = new StringTokenizer(memberName, ".");
					IEnumerator enumerator = parser.GetEnumerator();

					while (enumerator.MoveNext()) 
					{
						memberName = (string)enumerator.Current;
						type = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
					}
				} 
				else 
				{
					type = ReflectionInfo.GetInstance(type).GetGetterType(memberName);
				}
			}

			return type;
		}
Exemplo n.º 52
0
        /** Creates a CJK font.
         * @param fontName the name of the font
         * @param enc the encoding of the font
         * @param emb always <CODE>false</CODE>. CJK font and not embedded
         * @throws DocumentException on error
         * @throws IOException on error
         */
        internal CJKFont(string fontName, string enc, bool emb)
        {
            LoadProperties();
            this.FontType = FONT_TYPE_CJK;
            string nameBase = GetBaseName(fontName);

            if (!IsCJKFont(nameBase, enc))
            {
                throw new DocumentException("Font '" + fontName + "' with '" + enc + "' encoding is not a CJK font.");
            }
            if (nameBase.Length < fontName.Length)
            {
                style    = fontName.Substring(nameBase.Length);
                fontName = nameBase;
            }
            this.fontName = fontName;
            encoding      = CJK_ENCODING;
            vertical      = enc.EndsWith("V");
            CMap          = enc;
            if (enc.StartsWith("Identity-"))
            {
                cidDirect = true;
                string s = cjkFonts[fontName];
                s = s.Substring(0, s.IndexOf('_'));
                char[] c = (char[])allCMaps[s];
                if (c == null)
                {
                    c = ReadCMap(s);
                    if (c == null)
                    {
                        throw new DocumentException("The cmap " + s + " does not exist as a resource.");
                    }
                    c[CID_NEWLINE] = '\n';
                    allCMaps.Add(s, c);
                }
                translationMap = c;
            }
            else
            {
                char[] c = (char[])allCMaps[enc];
                if (c == null)
                {
                    string s = cjkEncodings[enc];
                    if (s == null)
                    {
                        throw new DocumentException("The resource cjkencodings.properties does not contain the encoding " + enc);
                    }
                    StringTokenizer tk = new StringTokenizer(s);
                    string          nt = tk.NextToken();
                    c = (char[])allCMaps[nt];
                    if (c == null)
                    {
                        c = ReadCMap(nt);
                        allCMaps.Add(nt, c);
                    }
                    if (tk.HasMoreTokens())
                    {
                        string nt2 = tk.NextToken();
                        char[] m2  = ReadCMap(nt2);
                        for (int k = 0; k < 0x10000; ++k)
                        {
                            if (m2[k] == 0)
                            {
                                m2[k] = c[k];
                            }
                        }
                        allCMaps.Add(enc, m2);
                        c = m2;
                    }
                }
                translationMap = c;
            }
            fontDesc = (Hashtable)allFonts[fontName];
            if (fontDesc == null)
            {
                fontDesc = ReadFontProperties(fontName);
                allFonts.Add(fontName, fontDesc);
            }
            hMetrics = (IntHashtable)fontDesc["W"];
            vMetrics = (IntHashtable)fontDesc["W2"];
        }
Exemplo n.º 53
0
		/// <summary>
		///  Returns the MemberInfo of the set member on the specified type.
		/// </summary>
		/// <param name="type">The type to check</param>
		/// <param name="memberName">The name of the member</param>
		/// <returns>The type of the member</returns>
		public static MemberInfo GetMemberInfoForSetter(Type type, string memberName) 
		{
			MemberInfo memberInfo =null;
			if (memberName.IndexOf('.') > -1) 
			{
				StringTokenizer parser = new StringTokenizer(memberName, ".");
				IEnumerator enumerator = parser.GetEnumerator();
				Type parentType = null;

				while (enumerator.MoveNext()) 
				{
					memberName = (string)enumerator.Current;
					parentType = type;
					type = ReflectionInfo.GetInstance(type).GetSetterType(memberName);
				}
				memberInfo = ReflectionInfo.GetInstance(parentType).GetSetter(memberName);
			} 
			else 
			{
				memberInfo = ReflectionInfo.GetInstance(type).GetSetter(memberName);
			}

			return memberInfo;
		}
Exemplo n.º 54
0
    /// <inheritdoc />
    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        if (context == null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        if (output == null)
        {
            throw new ArgumentNullException(nameof(output));
        }

        // Always strip the outer tag name as we never want <environment> to render
        output.TagName = null;

        if (string.IsNullOrWhiteSpace(Names) && string.IsNullOrWhiteSpace(Include) && string.IsNullOrWhiteSpace(Exclude))
        {
            // No names specified, do nothing
            return;
        }

        var currentEnvironmentName = HostingEnvironment.EnvironmentName?.Trim();

        if (string.IsNullOrEmpty(currentEnvironmentName))
        {
            // No current environment name, do nothing
            return;
        }

        if (Exclude != null)
        {
            var tokenizer = new StringTokenizer(Exclude, NameSeparator);
            foreach (var item in tokenizer)
            {
                var environment = item.Trim();
                if (environment.HasValue && environment.Length > 0)
                {
                    if (environment.Equals(currentEnvironmentName, StringComparison.OrdinalIgnoreCase))
                    {
                        // Matching environment name found, suppress output
                        output.SuppressOutput();
                        return;
                    }
                }
            }
        }

        var hasEnvironments = false;

        if (Names != null)
        {
            var tokenizer = new StringTokenizer(Names, NameSeparator);
            foreach (var item in tokenizer)
            {
                var environment = item.Trim();
                if (environment.HasValue && environment.Length > 0)
                {
                    hasEnvironments = true;
                    if (environment.Equals(currentEnvironmentName, StringComparison.OrdinalIgnoreCase))
                    {
                        // Matching environment name found, do nothing
                        return;
                    }
                }
            }
        }

        if (Include != null)
        {
            var tokenizer = new StringTokenizer(Include, NameSeparator);
            foreach (var item in tokenizer)
            {
                var environment = item.Trim();
                if (environment.HasValue && environment.Length > 0)
                {
                    hasEnvironments = true;
                    if (environment.Equals(currentEnvironmentName, StringComparison.OrdinalIgnoreCase))
                    {
                        // Matching environment name found, do nothing
                        return;
                    }
                }
            }
        }

        if (hasEnvironments)
        {
            // This instance had at least one non-empty environment (names or include) specified but none of these
            // environments matched the current environment. Suppress the output in this case.
            output.SuppressOutput();
        }
    }
Exemplo n.º 55
0
        /// <summary>
        /// Sets the member value.
        /// </summary>
        /// <param name="obj">he Object on which to invoke the specified mmber.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="memberValue">The member value.</param>
        /// <param name="objectFactory">The object factory.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
        public static void SetMemberValue(object obj, string memberName, object memberValue,
			IObjectFactory objectFactory,
            AccessorFactory accessorFactory)
		{
			if (memberName.IndexOf('.') > -1) 
			{
				StringTokenizer parser = new StringTokenizer(memberName, ".");
				IEnumerator enumerator = parser.GetEnumerator();
				enumerator.MoveNext();

				string currentPropertyName = (string)enumerator.Current;
				object child = obj;
      
				while (enumerator.MoveNext()) 
				{
					Type type = GetMemberTypeForSetter(child, currentPropertyName);
					object parent = child;
                    child = GetMember(parent, currentPropertyName, accessorFactory);
					if (child == null) 
					{
						try 
						{
							IFactory factory = objectFactory.CreateFactory(type, Type.EmptyTypes);
							child = factory.CreateInstance(Type.EmptyTypes);

                            SetMemberValue(parent, currentPropertyName, child, objectFactory, accessorFactory);
						} 
						catch (Exception e) 
						{
							throw new ProbeException("Cannot set value of property '" + memberName + "' because '" + currentPropertyName + "' is null and cannot be instantiated on instance of " + type.Name + ". Cause:" + e.Message, e);
						}
					}
					currentPropertyName = (string)enumerator.Current;
				}
                SetMember(child, currentPropertyName, memberValue, accessorFactory);
			} 
			else 
			{
                SetMember(obj, memberName, memberValue, accessorFactory);
			}
		}
Exemplo n.º 56
0
 internal static void CreateOutlineAction(PdfDictionary outline, Dictionary <String, Object> map, PdfWriter writer, bool namedAsNames)
 {
     try {
         String action = GetVal(map, "Action");
         if ("GoTo".Equals(action))
         {
             String p;
             if ((p = GetVal(map, "Named")) != null)
             {
                 if (namedAsNames)
                 {
                     outline.Put(PdfName.DEST, new PdfName(p));
                 }
                 else
                 {
                     outline.Put(PdfName.DEST, new PdfString(p, null));
                 }
             }
             else if ((p = GetVal(map, "Page")) != null)
             {
                 PdfArray        ar = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(p);
                 int             n  = int.Parse(tk.NextToken());
                 ar.Add(writer.GetPageReference(n));
                 if (!tk.HasMoreTokens())
                 {
                     ar.Add(PdfName.XYZ);
                     ar.Add(new float[] { 0, 10000, 0 });
                 }
                 else
                 {
                     String fn = tk.NextToken();
                     if (fn.StartsWith("/"))
                     {
                         fn = fn.Substring(1);
                     }
                     ar.Add(new PdfName(fn));
                     for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k)
                     {
                         fn = tk.NextToken();
                         if (fn.Equals("null"))
                         {
                             ar.Add(PdfNull.PDFNULL);
                         }
                         else
                         {
                             ar.Add(new PdfNumber(fn));
                         }
                     }
                 }
                 outline.Put(PdfName.DEST, ar);
             }
         }
         else if ("GoToR".Equals(action))
         {
             String        p;
             PdfDictionary dic = new PdfDictionary();
             if ((p = GetVal(map, "Named")) != null)
             {
                 dic.Put(PdfName.D, new PdfString(p, null));
             }
             else if ((p = GetVal(map, "NamedN")) != null)
             {
                 dic.Put(PdfName.D, new PdfName(p));
             }
             else if ((p = GetVal(map, "Page")) != null)
             {
                 PdfArray        ar = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(p);
                 ar.Add(new PdfNumber(tk.NextToken()));
                 if (!tk.HasMoreTokens())
                 {
                     ar.Add(PdfName.XYZ);
                     ar.Add(new float[] { 0, 10000, 0 });
                 }
                 else
                 {
                     String fn = tk.NextToken();
                     if (fn.StartsWith("/"))
                     {
                         fn = fn.Substring(1);
                     }
                     ar.Add(new PdfName(fn));
                     for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k)
                     {
                         fn = tk.NextToken();
                         if (fn.Equals("null"))
                         {
                             ar.Add(PdfNull.PDFNULL);
                         }
                         else
                         {
                             ar.Add(new PdfNumber(fn));
                         }
                     }
                 }
                 dic.Put(PdfName.D, ar);
             }
             String file = GetVal(map, "File");
             if (dic.Size > 0 && file != null)
             {
                 dic.Put(PdfName.S, PdfName.GOTOR);
                 dic.Put(PdfName.F, new PdfString(file));
                 String nw = GetVal(map, "NewWindow");
                 if (nw != null)
                 {
                     if (nw.Equals("true"))
                     {
                         dic.Put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
                     }
                     else if (nw.Equals("false"))
                     {
                         dic.Put(PdfName.NEWWINDOW, PdfBoolean.PDFFALSE);
                     }
                 }
                 outline.Put(PdfName.A, dic);
             }
         }
         else if ("URI".Equals(action))
         {
             String uri = GetVal(map, "URI");
             if (uri != null)
             {
                 PdfDictionary dic = new PdfDictionary();
                 dic.Put(PdfName.S, PdfName.URI);
                 dic.Put(PdfName.URI, new PdfString(uri));
                 outline.Put(PdfName.A, dic);
             }
         }
         else if ("JS".Equals(action))
         {
             String code = GetVal(map, "Code");
             if (code != null)
             {
                 outline.Put(PdfName.A, PdfAction.JavaScript(code, writer));
             }
         }
         else if ("Launch".Equals(action))
         {
             String file = GetVal(map, "File");
             if (file != null)
             {
                 PdfDictionary dic = new PdfDictionary();
                 dic.Put(PdfName.S, PdfName.LAUNCH);
                 dic.Put(PdfName.F, new PdfString(file));
                 outline.Put(PdfName.A, dic);
             }
         }
     }
     catch  {
         // empty on purpose
     }
 }
Exemplo n.º 57
0
        /// <summary> Reads the connection rule data file, and initialize the object.</summary>
        /// <param name="filePath">- the path for the connection rule file
        /// </param>
        /// <param name="tagCount">- the number of total tags in the tag set
        /// </param>
        /// <param name="tagSet">- the tag set which is used in the connection rules
        /// </param>
        /// <throws>  IOException </throws>
        private void readFile(System.String filePath, int tagCount, TagSet tagSet)
        {
            System.IO.StreamReader br = new System.IO.StreamReader(
                new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read),
                System.Text.Encoding.UTF8);
            System.String line = null;
            HashSet<int> tagSetA = new HashSet<int>();
            HashSet<int> tagSetB = new HashSet<int>();

            title = "";
            version = "";
            copyright = "";
            author = "";
            date = "";
            editor = "";
            startTag = "";
            connectionTable = new bool[tagCount][];
            for (int i = 0; i < tagCount; i++)
            {
                connectionTable[i] = new bool[tagCount];
            }

            for (int i = 0; i < tagCount; i++)
            {
                for (int j = 0; j < tagCount; j++)
                {
                    connectionTable[i][j] = false;
                }
            }

            while ((line = br.ReadLine()) != null)
            {
                StringTokenizer lineTokenizer = new StringTokenizer(line, "\t");
                if (lineTokenizer.HasMoreTokens == false)
                {
                    continue;
                }

                System.String lineToken = lineTokenizer.NextToken;

                if (lineToken.StartsWith("@"))
                {
                    if ("@title".Equals(lineToken))
                    {
                        title = lineTokenizer.NextToken;
                    }
                    else if ("@version".Equals(lineToken))
                    {
                        version = lineTokenizer.NextToken;
                    }
                    else if ("@copyright".Equals(lineToken))
                    {
                        copyright = lineTokenizer.NextToken;
                    }
                    else if ("@author".Equals(lineToken))
                    {
                        author = lineTokenizer.NextToken;
                    }
                    else if ("@date".Equals(lineToken))
                    {
                        date = lineTokenizer.NextToken;
                    }
                    else if ("@editor".Equals(lineToken))
                    {
                        editor = lineTokenizer.NextToken;
                    }
                }
                else if ("CONNECTION".Equals(lineToken))
                {
                    lineToken = lineTokenizer.NextToken;
                    System.String[] tagLists = lineToken.Split("\\*", 2);

                    StringTokenizer tagTokenizer = new StringTokenizer(tagLists[0], ",()");
                    while (tagTokenizer.HasMoreTokens)
                    {
                        System.String tagToken = tagTokenizer.NextToken;

                        StringTokenizer tok = new StringTokenizer(tagToken, "-");
                        while (tok.HasMoreTokens)
                        {
                            System.String t = tok.NextToken;
                            int[] fullTagIDSet = tagSet.getTags(t);

                            if (fullTagIDSet != null)
                            {
                                for (int i = 0; i < fullTagIDSet.Length; i++)
                                {
                                    tagSetA.Add(fullTagIDSet[i]);
                                }
                            }
                            else
                            {
                                tagSetA.Add(tagSet.getTagID(t));
                            }
                            while (tok.HasMoreTokens)
                            {
                                tagSetA.Remove(tagSet.getTagID(tok.NextToken));
                            }
                        }
                    }

                    tagTokenizer = new StringTokenizer(tagLists[1], ",()");
                    while (tagTokenizer.HasMoreTokens)
                    {
                        System.String tagToken = tagTokenizer.NextToken;

                        StringTokenizer tok = new StringTokenizer(tagToken, "-");
                        while (tok.HasMoreTokens)
                        {
                            System.String t = tok.NextToken;
                            int[] fullTagIDSet = tagSet.getTags(t);

                            if (fullTagIDSet != null)
                            {
                                for (int i = 0; i < fullTagIDSet.Length; i++)
                                {
                                    tagSetB.Add(fullTagIDSet[i]);
                                }
                            }
                            else
                            {
                                tagSetB.Add(tagSet.getTagID(t));
                            }
                            while (tok.HasMoreTokens)
                            {
                                tagSetB.Remove(tagSet.getTagID(tok.NextToken));
                            }
                        }
                    }

                    IEnumerator<int> iterA = tagSetA.GetEnumerator();
                    while (iterA.MoveNext())
                    {
                        int leftSide = iterA.Current;
                        IEnumerator<int> iterB = tagSetB.GetEnumerator();

                        while (iterB.MoveNext())
                        {
                            connectionTable[leftSide][iterB.Current] = true;
                        }
                    }

                    tagSetA.Clear();
                    tagSetB.Clear();
                }
                else if ("START_TAG".Equals(lineToken))
                {
                    startTag = lineTokenizer.NextToken;
                }
            }
            br.Close();
        }
Exemplo n.º 58
0
        public static Object[] IterateOutlines(PdfWriter writer, PdfIndirectReference parent, IList <Dictionary <String, Object> > kids, bool namedAsNames)
        {
            PdfIndirectReference[] refs = new PdfIndirectReference[kids.Count];
            for (int k = 0; k < refs.Length; ++k)
            {
                refs[k] = writer.PdfIndirectReference;
            }
            int ptr   = 0;
            int count = 0;

            foreach (Dictionary <String, Object> map in kids)
            {
                Object[] lower = null;
                IList <Dictionary <String, Object> > subKid = null;
                if (map.ContainsKey("Kids"))
                {
                    subKid = (IList <Dictionary <String, Object> >)map["Kids"];
                }
                if (subKid != null && subKid.Count > 0)
                {
                    lower = IterateOutlines(writer, refs[ptr], subKid, namedAsNames);
                }
                PdfDictionary outline = new PdfDictionary();
                ++count;
                if (lower != null)
                {
                    outline.Put(PdfName.FIRST, (PdfIndirectReference)lower[0]);
                    outline.Put(PdfName.LAST, (PdfIndirectReference)lower[1]);
                    int n = (int)lower[2];
                    if (map.ContainsKey("Open") && "false".Equals(map["Open"]))
                    {
                        outline.Put(PdfName.COUNT, new PdfNumber(-n));
                    }
                    else
                    {
                        outline.Put(PdfName.COUNT, new PdfNumber(n));
                        count += n;
                    }
                }
                outline.Put(PdfName.PARENT, parent);
                if (ptr > 0)
                {
                    outline.Put(PdfName.PREV, refs[ptr - 1]);
                }
                if (ptr < refs.Length - 1)
                {
                    outline.Put(PdfName.NEXT, refs[ptr + 1]);
                }
                outline.Put(PdfName.TITLE, new PdfString((String)map["Title"], PdfObject.TEXT_UNICODE));
                String color = null;
                if (map.ContainsKey("Color"))
                {
                    color = (String)map["Color"];
                }
                if (color != null)
                {
                    try {
                        PdfArray        arr = new PdfArray();
                        StringTokenizer tk  = new StringTokenizer(color);
                        for (int k = 0; k < 3; ++k)
                        {
                            float f = float.Parse(tk.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                            if (f < 0)
                            {
                                f = 0;
                            }
                            if (f > 1)
                            {
                                f = 1;
                            }
                            arr.Add(new PdfNumber(f));
                        }
                        outline.Put(PdfName.C, arr);
                    } catch {} //in case it's malformed
                }
                String style = GetVal(map, "Style");
                if (style != null)
                {
                    style = style.ToLower(System.Globalization.CultureInfo.InvariantCulture);
                    int bits = 0;
                    if (style.IndexOf("italic") >= 0)
                    {
                        bits |= 1;
                    }
                    if (style.IndexOf("bold") >= 0)
                    {
                        bits |= 2;
                    }
                    if (bits != 0)
                    {
                        outline.Put(PdfName.F, new PdfNumber(bits));
                    }
                }
                CreateOutlineAction(outline, map, writer, namedAsNames);
                writer.AddToBody(outline, refs[ptr]);
                ++ptr;
            }
            return(new Object[] { refs[0], refs[refs.Length - 1], count });
        }
Exemplo n.º 59
0
			public virtual void onClick(DialogInterface dialog, int which)
			{
				EditText editText = (EditText) view.findViewById(R.id.editText1);
				string @string = editText.Text.ToString();
				StringTokenizer stringTokenize = new StringTokenizer(@string);

				List<sbyte?> arrayList = new List<sbyte?>();
				while (stringTokenize.hasMoreTokens())
				{
					try
					{
						sbyte b = sbyte.Parse(stringTokenize.nextToken(), 16);
						arrayList.Add(b);
					}
					catch (System.FormatException e)
					{
						Console.WriteLine(e.ToString());
						Console.Write(e.StackTrace);
						Toast.makeText(context, "Invalid command!", Toast.LENGTH_SHORT).show();
						return;
					}
				}

				CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox1);
				bool hasResponse = checkBox.Checked;

				if (arrayList.Count > 0)
				{
					ByteBuffer buffer = ByteBuffer.allocate(arrayList.Count);
					for (int i = 0; i < arrayList.Count; i++)
					{
						buffer.put(arrayList[i]);
					}

					MainActivity.mBixolonPrinter.executeDirectIo(buffer.array(), hasResponse);
				}

			}
        internal void MergeField(String name, AcroFields.Item item)
        {
            Hashtable       map = fieldTree;
            StringTokenizer tk  = new StringTokenizer(name, ".");

            if (!tk.HasMoreTokens())
            {
                return;
            }
            while (true)
            {
                String s   = tk.NextToken();
                Object obj = map[s];
                if (tk.HasMoreTokens())
                {
                    if (obj == null)
                    {
                        obj    = new Hashtable();
                        map[s] = obj;
                        map    = (Hashtable)obj;
                        continue;
                    }
                    else if (obj is Hashtable)
                    {
                        map = (Hashtable)obj;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (obj is Hashtable)
                    {
                        return;
                    }
                    PdfDictionary merged = item.GetMerged(0);
                    if (obj == null)
                    {
                        PdfDictionary field = new PdfDictionary();
                        if (PdfName.SIG.Equals(merged.Get(PdfName.FT)))
                        {
                            hasSignature = true;
                        }
                        foreach (PdfName key in merged.Keys)
                        {
                            if (fieldKeys.ContainsKey(key))
                            {
                                field.Put(key, merged.Get(key));
                            }
                        }
                        ArrayList list = new ArrayList();
                        list.Add(field);
                        CreateWidgets(list, item);
                        map[s] = list;
                    }
                    else
                    {
                        ArrayList     list  = (ArrayList)obj;
                        PdfDictionary field = (PdfDictionary)list[0];
                        PdfName       type1 = (PdfName)field.Get(PdfName.FT);
                        PdfName       type2 = (PdfName)merged.Get(PdfName.FT);
                        if (type1 == null || !type1.Equals(type2))
                        {
                            return;
                        }
                        int       flag1 = 0;
                        PdfObject f1    = field.Get(PdfName.FF);
                        if (f1 != null && f1.IsNumber())
                        {
                            flag1 = ((PdfNumber)f1).IntValue;
                        }
                        int       flag2 = 0;
                        PdfObject f2    = merged.Get(PdfName.FF);
                        if (f2 != null && f2.IsNumber())
                        {
                            flag2 = ((PdfNumber)f2).IntValue;
                        }
                        if (type1.Equals(PdfName.BTN))
                        {
                            if (((flag1 ^ flag2) & PdfFormField.FF_PUSHBUTTON) != 0)
                            {
                                return;
                            }
                            if ((flag1 & PdfFormField.FF_PUSHBUTTON) == 0 && ((flag1 ^ flag2) & PdfFormField.FF_RADIO) != 0)
                            {
                                return;
                            }
                        }
                        else if (type1.Equals(PdfName.CH))
                        {
                            if (((flag1 ^ flag2) & PdfFormField.FF_COMBO) != 0)
                            {
                                return;
                            }
                        }
                        CreateWidgets(list, item);
                    }
                    return;
                }
            }
        }