Ejemplo n.º 1
0
		private AstRoot Parse(CharSequence cs)
		{
			CompilerEnvirons compilerEnv = new CompilerEnvirons();
			compilerEnv.InitFromContext(cx);
			ErrorReporter compilationErrorReporter = compilerEnv.GetErrorReporter();
			Parser p = new Parser(compilerEnv, compilationErrorReporter);
			return p.Parse(cs.ToString(), "<eval>", 1);
		}
Ejemplo n.º 2
0
        /// <summary>Tokenizes the text and returns an array of tokens.</summary>
        /// <remarks>Tokenizes the text and returns an array of tokens.</remarks>
        /// <param name="text">The text</param>
        /// <returns>The tokens</returns>
        public static string[] Tokenize(CharSequence text)
        {
            string replaced = text.ToString().ReplaceAll(RE_U00A0, "'\u00A0'");
            string match1 = PAT_WORD_BOUNDARY.Matcher(replaced).ReplaceAll("\u2063");
            string match2 = PAT_NOT_WORD_BOUNDARY.Matcher(match1).ReplaceAll("$1");

            string replaced2 = match2.ReplaceAll(RE_U2063, " ");
            string trimmed = replaced2.Trim();
            //string[] parts = trimmed.Split("[ ]+");
            string[] parts = RE_SPACE_SPLITTER.Split(trimmed);

            return parts;
        }
Ejemplo n.º 3
0
		private string Flatten()
		{
			lock (this)
			{
				if (depth > 0)
				{
					StringBuilder b = new StringBuilder(length);
					AppendTo(b);
					s1 = b.ToString();
					s2 = string.Empty;
					depth = 0;
				}
				return (string)s1;
			}
		}
Ejemplo n.º 4
0
			/// <summary>
			/// Compiles
			/// <code>source</code>
			/// and returns the transformed and optimized
			/// <see cref="Rhino.Ast.ScriptNode">Rhino.Ast.ScriptNode</see>
			/// </summary>
			protected internal virtual ScriptNode Compile(CharSequence source)
			{
				string mainMethodClassName = "Main";
				string scriptClassName = "Main";
				CompilerEnvirons compilerEnv = new CompilerEnvirons();
				compilerEnv.InitFromContext(cx);
				ErrorReporter compilationErrorReporter = compilerEnv.GetErrorReporter();
				Parser p = new Parser(compilerEnv, compilationErrorReporter);
				AstRoot ast = p.Parse(source.ToString(), "<eval>", 1);
				IRFactory irf = new IRFactory(compilerEnv);
				ScriptNode tree = irf.TransformTree(ast);
				Codegen codegen = new Codegen();
				codegen.SetMainMethodClass(mainMethodClassName);
				codegen.CompileToClassFile(compilerEnv, scriptClassName, tree, tree.GetEncodedSource(), false);
				return tree;
			}
Ejemplo n.º 5
0
		// COPY: Partially copied from android.text.TextUtils
		/// <summary>Returns a string containing the tokens joined by delimiters.</summary>
		/// <remarks>Returns a string containing the tokens joined by delimiters.</remarks>
		/// <param name="tokens">
		/// an array objects to be joined. Strings will be formed from
		/// the objects by calling object.toString().
		/// </param>
		public static string Join(CharSequence delimiter, IEnumerable tokens)
		{
			StringBuilder sb = new StringBuilder();
			bool firstTime = true;
			foreach (object token in tokens)
			{
				if (firstTime)
				{
					firstTime = false;
				}
				else
				{
					sb.Append(delimiter);
				}
				sb.Append(token);
			}
			return sb.ToString();
		}
Ejemplo n.º 6
0
		public ConsString(CharSequence str1, CharSequence str2)
		{
			s1 = str1;
			s2 = str2;
			length = str1.Length + str2.Length;
			depth = 1;
			if (str1 is Rhino.ConsString)
			{
				depth += ((Rhino.ConsString)str1).depth;
			}
			if (str2 is Rhino.ConsString)
			{
				depth += ((Rhino.ConsString)str2).depth;
			}
			// Don't let it grow too deep, can cause stack overflows
			if (depth > 2000)
			{
				Flatten();
			}
		}
Ejemplo n.º 7
0
		private static bool EqString(CharSequence x, object y)
		{
			for (; ; )
			{
				if (y == null || y == Undefined.instance)
				{
					return false;
				}
				else
				{
					if (y is CharSequence)
					{
						CharSequence c = (CharSequence)y;
						return x.Length == c.Length && x.ToString().Equals(c.ToString());
					}
					else
					{
						if (y is Number)
						{
							return ToNumber(x.ToString()) == System.Convert.ToDouble(((Number)y));
						}
						else
						{
							if (y is bool)
							{
								return ToNumber(x.ToString()) == (((bool)y) ? 1.0 : 0.0);
							}
							else
							{
								if (y is Scriptable)
								{
									if (y is ScriptableObject)
									{
										object test = ((ScriptableObject)y).EquivalentValues(x.ToString());
										if (test != ScriptableConstants.NOT_FOUND)
										{
											return ((bool)test);
										}
									}
									y = ToPrimitive(y);
									continue;
								}
								else
								{
									WarnAboutNonJSObject(y);
									return false;
								}
							}
						}
					}
				}
			}
		}
Ejemplo n.º 8
0
		public static CharSequence Add(object val1, CharSequence val2)
		{
			return new ConsString(ToCharSequence(val1), val2);
		}
Ejemplo n.º 9
0
		public static CharSequence Add(CharSequence val1, object val2)
		{
			return new ConsString(val1, ToCharSequence(val2));
		}
Ejemplo n.º 10
0
		private static CharSequence Js_substring(Context cx, CharSequence target, object[] args)
		{
			int length = target.Length;
			double start = ScriptRuntime.ToInteger(args, 0);
			double end;
			if (start < 0)
			{
				start = 0;
			}
			else
			{
				if (start > length)
				{
					start = length;
				}
			}
			if (args.Length <= 1 || args[1] == Undefined.instance)
			{
				end = length;
			}
			else
			{
				end = ScriptRuntime.ToInteger(args[1]);
				if (end < 0)
				{
					end = 0;
				}
				else
				{
					if (end > length)
					{
						end = length;
					}
				}
				// swap if end < start
				if (end < start)
				{
					if (cx.GetLanguageVersion() != Context.VERSION_1_2)
					{
						double temp = start;
						start = end;
						end = temp;
					}
					else
					{
						// Emulate old JDK1.0 java.lang.String.substring()
						end = start;
					}
				}
			}
			return target.SubSequence((int)start, (int)end);
		}
Ejemplo n.º 11
0
			/// <exception cref="System.IO.IOException"></exception>
			protected internal override void WriteOne(CharSequence line)
			{
				pckOut.WriteString(line.ToString());
			}
Ejemplo n.º 12
0
		public ByteBuffer Encode (CharSequence str)
		{
			return Encode (str.ToString ());
		}
Ejemplo n.º 13
0
		/// <summary>Tokenizes the text and returns an array of tokens.</summary>
		/// <remarks>Tokenizes the text and returns an array of tokens.</remarks>
		/// <param name="text">The text</param>
		/// <returns>The tokens</returns>
		public static string[] Tokenize(CharSequence text)
		{
			return PAT_NOT_WORD_BOUNDARY.Matcher(PAT_WORD_BOUNDARY.Matcher(text.ToString().ReplaceAll ("\u00A0","'\u00A0'")).ReplaceAll("\u2063"
				)).ReplaceAll("$1").ReplaceAll("[ \u2063]+", " ").Trim().Split("[ ]+");
		}
Ejemplo n.º 14
0
		private object Eval(CharSequence cs)
		{
			return cx.EvaluateString(scope, cs.ToString(), "<eval>", 1, null);
		}
Ejemplo n.º 15
0
 private bool IsClause(CharSequence text)
 {
     Matcher m = PAT_WHITESPACE.Matcher(text.ToString());
     int n = 1;
     while (m.Find())
     {
         n++;
         if (n >= minWords)
         {
             return true;
         }
     }
     return n >= minWords;
 }
Ejemplo n.º 16
0
 public virtual void MergeNext(NBoilerpipe.Document.TextBlock other)
 {
     StringBuilder sb = new StringBuilder ();
     sb.Append (text);
     sb.Append ('\n');
     sb.Append (other.text);
     this.text = sb.ToString ();
     numWords += other.numWords;
     numWordsInAnchorText += other.numWordsInAnchorText;
     numWordsInWrappedLines += other.numWordsInWrappedLines;
     numWrappedLines += other.numWrappedLines;
     offsetBlocksStart = Math.Min (offsetBlocksStart, other.offsetBlocksStart);
     offsetBlocksEnd = Math.Max (offsetBlocksEnd, other.offsetBlocksEnd);
     InitDensities ();
     this.isContent |= other.isContent;
     if (containedTextElements == null) {
         containedTextElements = (BitSet)other.containedTextElements.Clone ();
     } else {
         containedTextElements.Or (other.containedTextElements);
     }
     numFullTextWords += other.numFullTextWords;
     if (other.labels != null) {
         if (labels == null) {
             labels = new HashSet<string> (other.labels);
         } else {
             Sharpen.Collections.AddAll (labels, other.labels);
         }
     }
     tagLevel = Math.Min (tagLevel, other.tagLevel);
 }
Ejemplo n.º 17
0
		private static CharSequence Js_slice(CharSequence target, object[] args)
		{
			if (args.Length != 0)
			{
				double begin = ScriptRuntime.ToInteger(args[0]);
				double end;
				int length = target.Length;
				if (begin < 0)
				{
					begin += length;
					if (begin < 0)
					{
						begin = 0;
					}
				}
				else
				{
					if (begin > length)
					{
						begin = length;
					}
				}
				if (args.Length == 1)
				{
					end = length;
				}
				else
				{
					end = ScriptRuntime.ToInteger(args[1]);
					if (end < 0)
					{
						end += length;
						if (end < 0)
						{
							end = 0;
						}
					}
					else
					{
						if (end > length)
						{
							end = length;
						}
					}
					if (end < begin)
					{
						end = begin;
					}
				}
				return target.SubSequence((int)begin, (int)end);
			}
			return target;
		}
Ejemplo n.º 18
0
			/// <summary>
			/// Checks every variable
			/// <code>v</code>
			/// in
			/// <code>source</code>
			/// is marked as a
			/// number-variable iff
			/// <code>numbers</code>
			/// contains
			/// <code>v</code>
			/// </summary>
			protected internal virtual void AssertNumberVars(CharSequence source, params string[] numbers)
			{
				// wrap source in function
				ScriptNode tree = Compile("function f(o, fn){" + source + "}");
				FunctionNode fnode = tree.GetFunctionNode(0);
				NUnit.Framework.Assert.IsNotNull(fnode);
				OptFunctionNode opt = OptFunctionNode.Get(fnode);
				NUnit.Framework.Assert.IsNotNull(opt);
				NUnit.Framework.Assert.AreSame(fnode, opt.fnode);
				for (int i = 0, c = fnode.GetParamCount(); i < c; ++i)
				{
					NUnit.Framework.Assert.IsTrue(opt.IsParameter(i));
					NUnit.Framework.Assert.IsFalse(opt.IsNumberVar(i));
				}
				ICollection<string> set = new HashSet<string>(Arrays.AsList(numbers));
				for (int i_1 = fnode.GetParamCount(), c_1 = fnode.GetParamAndVarCount(); i_1 < c_1; ++i_1)
				{
					NUnit.Framework.Assert.IsFalse(opt.IsParameter(i_1));
					string name = fnode.GetParamOrVarName(i_1);
					string msg = string.Format("{%s -> number? = %b}", name, opt.IsNumberVar(i_1));
					NUnit.Framework.Assert.AreEqual(set.Contains(name), opt.IsNumberVar(i_1), msg);
				}
			}
Ejemplo n.º 19
0
		public virtual void MergeNext (NBoilerpipePortable.Document.TextBlock other)
		{
            if (other.nearbyImages != null)
            {
                if (nearbyImages != null)
                    nearbyImages.AddRange(other.nearbyImages.Select(imgTpl => Tuple.Create(imgTpl.Item1 + text.Length, imgTpl.Item2)));
                else
                {
                    //rebase the image index off the current text length
                    nearbyImages = other.nearbyImages.Select(imgTpl => Tuple.Create(imgTpl.Item1 + text.Length, imgTpl.Item2)).ToList();
                }
            }

			StringBuilder sb = new StringBuilder ();
			sb.Append (text);
			sb.Append ('\n');
			sb.Append (other.text);
			this.text = sb.ToString ();
			numWords += other.numWords;
			numWordsInAnchorText += other.numWordsInAnchorText;
			numWordsInWrappedLines += other.numWordsInWrappedLines;
			numWrappedLines += other.numWrappedLines;
			offsetBlocksStart = Math.Min (offsetBlocksStart, other.offsetBlocksStart);
			offsetBlocksEnd = Math.Max (offsetBlocksEnd, other.offsetBlocksEnd);
			InitDensities ();
			this.isContent |= other.isContent;
			if (containedTextElements == null) {
				containedTextElements = (BitSet)other.containedTextElements.Clone ();
			} else {
				containedTextElements.Or (other.containedTextElements);
			}
			numFullTextWords += other.numFullTextWords;
			if (other.labels != null) {
				if (labels == null) {
					labels = new HashSet<string> (other.labels);
				} else {
                    foreach (var label in other.labels)
                        labels.Add(label);
				}
			}
			tagLevel = Math.Min (tagLevel, other.tagLevel);
            
		}
Ejemplo n.º 20
0
		/// <summary>Write a single advertisement line.</summary>
		/// <remarks>Write a single advertisement line.</remarks>
		/// <param name="line">
		/// the advertisement line to be written. The line always ends
		/// with LF. Never null or the empty string.
		/// </param>
		/// <exception cref="System.IO.IOException">
		/// the underlying output stream failed to write out an
		/// advertisement record.
		/// </exception>
		protected internal abstract void WriteOne(CharSequence line);
Ejemplo n.º 21
0
		private string ToSource(CharSequence cs)
		{
			return Parse(cs).ToSource();
		}
Ejemplo n.º 22
0
		private static void AppendFragment(CharSequence s, StringBuilder b)
		{
			if (s is Rhino.ConsString)
			{
				((Rhino.ConsString)s).AppendTo(b);
			}
			else
			{
				b.Append(s);
			}
		}
Ejemplo n.º 23
0
 public Matcher Reset (CharSequence str)
 {
     return Reset (str.ToString ());
 }
Ejemplo n.º 24
0
 public static ByteBuffer Encode(this Encoding e, CharSequence str)
 {
     return(ByteBuffer.Wrap(e.GetBytes(str.ToString())));
 }
Ejemplo n.º 25
0
		internal NativeString(CharSequence s)
		{
			@string = s;
		}