public static string Translate(string input, ILocalizerResolver resolver, string startTag, string endTag)
		{
			StringBuilder builder = new StringBuilder();
			using (StringReader reader = new StringReader(input))
			using (StringWriter writer = new StringWriter(builder))
				Translate(reader, writer, resolver, startTag, endTag);
			return builder.ToString();
		}
Exemplo n.º 2
0
        public static string Translate(string input, ILocalizerResolver resolver, string startTag, string endTag)
        {
            StringBuilder builder = new StringBuilder();

            using (StringReader reader = new StringReader(input))
                using (StringWriter writer = new StringWriter(builder))
                    Translate(reader, writer, resolver, startTag, endTag);
            return(builder.ToString());
        }
Exemplo n.º 3
0
        public static void Translate(TextReader input, TextWriter output, ILocalizerResolver resolver, string startTag, string endTag)
        {
            if (startTag.Length != 2)
            {
                throw new ApplicationException("Start Tag must be 2 characters");
            }
            if (endTag.Length != 1)
            {
                throw new ApplicationException("End Tag must be 1 character");
            }

            char[] buffer = new char[64];

            for (;;)
            {
                int c = input.Read();
                if (c == -1)
                {
                    break;
                }
                if (c != startTag[0] || input.Peek() != startTag[1])
                {
                    output.Write((char)c);
                }
                else
                {
                    input.Read();                     //consume the 2nd char of the startTag

                    //build the word we want to resolve
                    //if we hit EOF then it's just like we hit the endTag
                    // if we hit the endTag, resolve the word and write it to output
                    int pos = 0;
                    for (; ;)
                    {
                        c = input.Read();
                        if (c == -1 || c == endTag[0])                         //end of file is just like endTag or end tag found
                        {
                            break;
                        }

                        if (pos == buffer.Length)
                        {
                            Array.Resize(ref buffer, buffer.Length * 2);
                        }
                        buffer[pos++] = (char)c;
                    }

                    //resolve the word and write it to the output
                    string word   = new string(buffer, 0, pos);
                    string result = resolver.Resolve(word);
                    output.Write(result);
                }
            }
        }
		public static void Translate(TextReader input, TextWriter output, ILocalizerResolver resolver, string startTag, string endTag)
		{
			if (startTag.Length != 2)
				throw new ApplicationException("Start Tag must be 2 characters");
			if (endTag.Length != 1)
				throw new ApplicationException("End Tag must be 1 character");

			char[] buffer = new char[64];

			for (;;)
			{
				int c = input.Read();
				if (c == -1)
					break;
				if (c != startTag[0] || input.Peek() != startTag[1])
					output.Write((char)c);
				else
				{
					input.Read(); //consume the 2nd char of the startTag

					//build the word we want to resolve
					//if we hit EOF then it's just like we hit the endTag
					// if we hit the endTag, resolve the word and write it to output
					int pos = 0;
					for (; ; )
					{
						c = input.Read();
						if (c == -1 || c == endTag[0]) //end of file is just like endTag or end tag found
							break;

						if (pos == buffer.Length)
							Array.Resize(ref buffer, buffer.Length * 2);
						buffer[pos++] = (char)c;
					}

					//resolve the word and write it to the output
					string word = new string(buffer, 0, pos);
					string result = resolver.Resolve(word);
					output.Write(result);
				}
			}
		}