/// <summary> Match a String against the given pattern, supporting the following simple
 /// pattern styles: "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality.
 /// </summary>
 /// <param name="pattern">the pattern to match against
 /// </param>
 /// <param name="str">the String to match
 /// </param>
 /// <returns> whether the String matches the given pattern
 /// </returns>
 public static bool SimpleMatch(System.String pattern, System.String str)
 {
     if (ObjectUtils.NullSafeEquals(pattern, str) || "*".Equals(pattern))
     {
         return true;
     }
     if (pattern == null || str == null)
     {
         return false;
     }
     if (pattern.StartsWith("*") && pattern.EndsWith("*") &&
         str.IndexOf(pattern.Substring(1, (pattern.Length - 1) - (1))) != -1)
     {
         return true;
     }
     if (pattern.StartsWith("*") && str.EndsWith(pattern.Substring(1, (pattern.Length) - (1))))
     {
         return true;
     }
     if (pattern.EndsWith("*") && str.StartsWith(pattern.Substring(0, (pattern.Length - 1) - (0))))
     {
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
        public void StartsWithUsesSpecifiedEqualityComparerOrDefault()
        {
            var first = new[] {1,2,3};
            var second = new[] {4,5,6};

            Assert.False(first.StartsWith(second));
            Assert.False(first.StartsWith(second, null));
            Assert.False(first.StartsWith(second, new EqualityComparerFunc<int>((f, s) => false)));
            Assert.True(first.StartsWith(second, new EqualityComparerFunc<int>((f, s) => true)));
        }
Exemplo n.º 3
0
		/* (non-Javadoc)
		* @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
		*/
		public virtual bool Accept(System.IO.FileInfo dir, System.String name)
		{
			int i = name.LastIndexOf((System.Char) '.');
			if (i != - 1)
			{
				System.String extension = name.Substring(1 + i);
				if (extensions.Contains(extension))
				{
					return true;
				}
				else if (extension.StartsWith("f") && (new System.Text.RegularExpressions.Regex("f\\d+")).Match(extension).Success)
				{
					return true;
				}
				else if (extension.StartsWith("s") && (new System.Text.RegularExpressions.Regex("s\\d+")).Match(extension).Success)
				{
					return true;
				}
			}
			else
			{
				if (name.Equals(IndexFileNames.DELETABLE))
					return true;
				else if (name.StartsWith(IndexFileNames.SEGMENTS))
					return true;
			}
			return false;
		}
		/// <summary> Set the value of the attribute and the quote character.
		/// If the value is pure whitespace, assign it 'as is' and reset the
		/// quote character. If not, check for leading and trailing double or
		/// single quotes, and if found use this as the quote character and
		/// the inner contents of <code>value</code> as the real value.
		/// Otherwise, examine the string to determine if quotes are needed
		/// and an appropriate quote character if so. This may involve changing
		/// double quotes within the string to character references.
		/// </summary>
		/// <param name="value">The new value.
		/// </param>
		public virtual void SetRawValue(System.String value_Renamed)
		{
			char ch;
			bool needed;
			bool singleq;
			bool doubleq;
			System.String ref_Renamed;
			System.Text.StringBuilder buffer;
			char quote;
			
			quote = (char) (0);
			if ((null != value_Renamed) && (0 != value_Renamed.Trim().Length))
			{
				if (value_Renamed.StartsWith("'") && value_Renamed.EndsWith("'") && (2 <= value_Renamed.Length))
				{
					quote = '\'';
					value_Renamed = value_Renamed.Substring(1, (value_Renamed.Length - 1) - (1));
				}
				else if (value_Renamed.StartsWith("\"") && value_Renamed.EndsWith("\"") && (2 <= value_Renamed.Length))
				{
					quote = '"';
					value_Renamed = value_Renamed.Substring(1, (value_Renamed.Length - 1) - (1));
				}
				else
				{
					// first determine if there's whitespace in the value
					// and while we're at it find a suitable quote character
					needed = false;
					singleq = true;
					doubleq = true;
					for (int i = 0; i < value_Renamed.Length; i++)
					{
						ch = value_Renamed[i];
						if ('\'' == ch)
						{
							singleq = false;
							needed = true;
						}
						else if ('"' == ch)
						{
							doubleq = false;
							needed = true;
						}
						else if (!('-' == ch) && !('.' == ch) && !('_' == ch) && !(':' == ch) && !System.Char.IsLetterOrDigit(ch))
						{
							needed = true;
						}
					}
					
					// now apply quoting
					if (needed)
					{
						if (doubleq)
							quote = '"';
						else if (singleq)
							quote = '\'';
						else
						{
							// uh-oh, we need to convert some quotes into character
							// references, so convert all double quotes into &#34;
							quote = '"';
							ref_Renamed = "&quot;"; // Translate.encode (quote);
							// JDK 1.4: value = value.replaceAll ("\"", ref);
							buffer = new System.Text.StringBuilder(value_Renamed.Length * (ref_Renamed.Length - 1));
							for (int i = 0; i < value_Renamed.Length; i++)
							{
								ch = value_Renamed[i];
								if (quote == ch)
									buffer.Append(ref_Renamed);
								else
									buffer.Append(ch);
							}
							value_Renamed = buffer.ToString();
						}
					}
				}
			}
			SetValue(value_Renamed);
			SetQuote(quote);
		}
Exemplo n.º 5
0
		/// <summary> Returns a String representing the encoding of the given message, if
		/// the encoding is recognized.  For example if the given message appears
		/// to be encoded using HL7 2.x XML rules then "XML" would be returned.
		/// If the encoding is not recognized then null is returned.  That this
		/// method returns a specific encoding does not guarantee that the
		/// message is correctly encoded (e.g. well formed XML) - just that
		/// it is not encoded using any other encoding than the one returned.
		/// </summary>
		public override System.String getEncoding(System.String message)
		{
			System.String encoding = null;
			
			//quit if the string is too short
			if (message.Length < 4)
				return null;
			
			//see if it looks like this message is | encoded ...
			bool ok = true;
			
			//string should start with "MSH"
			if (!message.StartsWith("MSH"))
				return null;
			
			//4th character of each segment should be field delimiter
			char fourthChar = message[3];
			SupportClass.Tokenizer st = new SupportClass.Tokenizer(message, System.Convert.ToString(segDelim), false);
			while (st.HasMoreTokens())
			{
				System.String x = st.NextToken();
				if (x.Length > 0)
				{
					if (System.Char.IsWhiteSpace(x[0]))
						x = stripLeadingWhitespace(x);
					if (x.Length >= 4 && x[3] != fourthChar)
						return null;
				}
			}
			
			//should be at least 11 field delimiters (because MSH-12 is required)
			int nextFieldDelimLoc = 0;
			for (int i = 0; i < 11; i++)
			{
				nextFieldDelimLoc = message.IndexOf((System.Char) fourthChar, nextFieldDelimLoc + 1);
				if (nextFieldDelimLoc < 0)
					return null;
			}
			
			if (ok)
				encoding = "VB";
			
			return encoding;
		}
Exemplo n.º 6
0
 public virtual bool matches(int lineNumber, System.String line)
 {
     if (line.StartsWith("_cell_length_a") || line.StartsWith("_audit_creation_date") || line.StartsWith("loop_"))
     {
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 /// <summary> Parse the generation off the segments file name and
 /// return it.
 /// </summary>
 public static long GenerationFromSegmentsFileName(System.String fileName)
 {
     if (fileName.Equals(IndexFileNames.SEGMENTS))
     {
         return 0;
     }
     else if (fileName.StartsWith(IndexFileNames.SEGMENTS))
     {
         return SupportClass.Number.ToInt64(fileName.Substring(1 + IndexFileNames.SEGMENTS.Length));
     }
     else
     {
         throw new System.ArgumentException("fileName \"" + fileName + "\" is not a segments file");
     }
 }
Exemplo n.º 8
0
 public virtual bool matches(int lineNumber, System.String line)
 {
     if (lineNumber == 1 && line.StartsWith("frame: "))
     {
         return true;
     }
     return false;
 }
Exemplo n.º 9
0
		/// <summary> Factory method for generating a query. Called when parser
		/// parses an input term token that contains one or more wildcard
		/// characters (? and *), but is not a prefix term token (one
		/// that has just a single * character at the end)
		/// <p/>
		/// Depending on settings, prefix term may be lower-cased
		/// automatically. It will not go through the default Analyzer,
		/// however, since normal Analyzers are unlikely to work properly
		/// with wildcard templates.
		/// <p/>
		/// Can be overridden by extending classes, to provide custom handling for
		/// wildcard queries, which may be necessary due to missing analyzer calls.
		/// 
		/// </summary>
		/// <param name="field">Name of the field query will use.
		/// </param>
		/// <param name="termStr">Term token that contains one or more wild card
		/// characters (? or *), but is not simple prefix term
		/// 
		/// </param>
		/// <returns> Resulting {@link Query} built for the term
		/// </returns>
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		public /*protected internal*/ virtual Query GetWildcardQuery(System.String field, System.String termStr)
		{
			if ("*".Equals(field))
			{
				if ("*".Equals(termStr))
					return NewMatchAllDocsQuery();
			}
			if (!allowLeadingWildcard && (termStr.StartsWith("*") || termStr.StartsWith("?")))
				throw new ParseException("'*' or '?' not allowed as first character in WildcardQuery");
			if (lowercaseExpandedTerms)
			{
				termStr = termStr.ToLower();
			}
			Term t = new Term(field, termStr);
			return NewWildcardQuery(t);
		}
Exemplo n.º 10
0
        /// <summary>
        /// Action: Search
        /// </summary>
        /// <param name="ContainerID">Associated State Variable: A_ARG_TYPE_ObjectID</param>
        /// <param name="SearchCriteria">Associated State Variable: A_ARG_TYPE_SearchCriteria</param>
        /// <param name="Filter">Associated State Variable: A_ARG_TYPE_Filter</param>
        /// <param name="StartingIndex">Associated State Variable: A_ARG_TYPE_Index</param>
        /// <param name="RequestedCount">Associated State Variable: A_ARG_TYPE_Count</param>
        /// <param name="SortCriteria">Associated State Variable: A_ARG_TYPE_SortCriteria</param>
        /// <param name="Result">Associated State Variable: A_ARG_TYPE_Result</param>
        /// <param name="NumberReturned">Associated State Variable: A_ARG_TYPE_Count</param>
        /// <param name="TotalMatches">Associated State Variable: A_ARG_TYPE_Count</param>
        /// <param name="UpdateID">Associated State Variable: A_ARG_TYPE_UpdateID</param>
        public void Search(System.String ContainerID, System.String SearchCriteria, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, out System.String Result, out System.UInt32 NumberReturned, out System.UInt32 TotalMatches, out System.UInt32 UpdateID)
        {
            // Action: Search
            // This action allows the caller to search the content directory for objects that match
            // some search criteria. The search criteria are specified as a query string operating on
            // properties with comparison and logical operators.
            Result = String.Empty;
            NumberReturned = 0;
            TotalMatches = 0;
            UpdateID = 0;

            //http://code.google.com/p/jems/wiki/XBox360Notes
            //4 audioItem
            //5 musicGenre
            //6 musicArtist
            //7 musicAlbum
            //F playlistContainer
            //14 folders
            if (ContainerID.StartsWith("0") == true ||
                ContainerID.StartsWith("4") == true ||
                ContainerID.StartsWith("5") == true ||
                ContainerID.StartsWith("6") == true ||
                ContainerID.StartsWith("7") == true ||
                ContainerID.StartsWith("F") == true ||
                ContainerID.StartsWith("14") == true)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(DidlHandler.BeginDidl());

                NumberReturned = 0;
                TotalMatches = 0;

                //if (SearchCriteria.IndexOf("upnp:class derivedfrom \"object.item.imageItem\"", StringComparison.InvariantCultureIgnoreCase) == -1 &&
                //    SearchCriteria.IndexOf("upnp:class derivedfrom \"object.item.videoItem\"", StringComparison.InvariantCultureIgnoreCase) == -1)
                if (SearchCriteria.IndexOf("upnp:class derivedfrom \"object.item.audioItem\"", StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    // Always JUMP to 4 !
                    ContainerID = "4";

                    if (ContainerID == "0")
                    {
                        //NumberReturned = 1;
                        TotalMatches = 1;
                        sb.AppendLine(DidlHandler.GetContainer("14", "0", "Music", "object.container.storageFolder"));
                        //Result = "<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\">" +
                        //    "<container id=\"14\" parentID=\"\" childCount=\"0\"><dc:title>Live Stream</dc:title><upnp:class>object.container.storageFolder</upnp:class></container>" +
                        //    //"<container id=\"15\" parentID=\"\" childCount=\"0\"><dc:title>Videos</dc:title><upnp:class>object.container.storageFolder</upnp:class></container>" +
                        //    //"<container id=\"16\" parentID=\"\" childCount=\"0\"><dc:title>Pictures</dc:title><upnp:class>object.container.storageFolder</upnp:class></container>" +
                        //    "</DIDL-Lite>";
                    }
                    else if (ContainerID == "4" || ContainerID == "5" || ContainerID == "6" || ContainerID == "7" || ContainerID == "14") //return all songs
                    {
                        sb.Append(this.GetMp3StreamItem());
                        sb.Append(this.GetL16StreamItem());

                        TotalMatches = 2;
                    }
                }

                //TODO respect # requested from client
                NumberReturned = TotalMatches;

                sb.Append(DidlHandler.EndDidl());
                Result = sb.ToString();
            }
        }
			/// <summary>  Returns <code>false</code> if the <code>robots.txt</code> file
			/// prohibits us from accessing the given <code>path</code>, or
			/// <code>true</code> otherwise.
			/// </summary>
			public virtual bool IsAllowed(System.String path)
			{
				try
				{
					path = HttpUtility.UrlDecode(path, System.Text.Encoding.GetEncoding(RobotRulesParser.CHARACTER_ENCODING.ToLower()));
				}
				catch (System.Exception e)
				{
					// just ignore it- we can still try to match 
					// path prefixes
				}
				
				if (m_entries == null)
				{
					m_entries = new RobotsEntry[m_tmpEntries.Count];
					m_entries = (RobotsEntry[]) Support.ICollectionSupport.ToArray(m_tmpEntries, m_entries);
					m_tmpEntries = null;
				}
				
				int pos = 0;
				int end = m_entries.Length;
				while (pos < end)
				{
					if (path.StartsWith(m_entries[pos].m_strPrefix))
						return m_entries[pos].m_bAllowed;
					pos++;
				}
				
				return true;
			}
Exemplo n.º 12
0
		public virtual bool matches(int lineNumber, System.String line)
		{
			if (line.StartsWith("!Header gpr"))
			{
				return true;
			}
			return false;
		}
Exemplo n.º 13
0
			public override void  Message(System.String message)
			{
				if (message.StartsWith("now flush at close") && 0 == thrown.Count)
				{
					thrown.Add(null);
					throw new System.OutOfMemoryException("fake OOME at " + message);
				}
			}
 public void ToFriendlyTypeNameShouldReturnProperNameWhenTypeIsAnonymousWithGeneric()
 {
     var name = new { Int = 1, String = "Test" }.GetType().ToFriendlyTypeName();
     Assert.True(name.StartsWith("AnonymousType"));
     Assert.True(name.EndsWith("<Int32, String>"));
 }
 public void ToFriendlyTypeNameShouldReturnProperNameWhenTypeIsAnonymous()
 {
     var name = new { }.GetType().ToFriendlyTypeName();
     Assert.True(name.StartsWith("AnonymousType"));
 }
Exemplo n.º 16
0
		public virtual bool matches(int lineNumber, System.String line)
		{
			// the below matching actually matches all RDF files
			if (line.StartsWith("$RDFILE "))
			{
				return true;
			}
			return false;
		}
Exemplo n.º 17
0
		public static int parseColor(System.String string_Renamed)
		{
			if (string_Renamed.Length > 0)
			{
				if (string_Renamed[0] == '#')
				{
					return (int) System.Convert.ToInt64(string_Renamed.Substring(1), 16);
				}
				else if (string_Renamed.StartsWith("0x") || string_Renamed.StartsWith("0X"))
				{
					//UPGRADE_TODO: Method 'java.lang.Integer.parseInt' was converted to 'System.Convert.ToInt32' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
					return System.Convert.ToInt32(string_Renamed.Substring(2), 16);
				}
				else
				{
					return System.Int32.Parse(string_Renamed);
				}
			}
			else
			{
				return 0;
			}
		}
Exemplo n.º 18
0
		public virtual bool matches(int lineNumber, System.String line)
		{
			if (lineNumber == 4 && (line.IndexOf("v2000") >= 0 || line.IndexOf("V2000") >= 0))
			{
				return true;
			}
			else if (line.StartsWith("M  END"))
			{
				return true;
			}
			else if (lineNumber == 4 && line.Length > 7)
			{
				// possibly a MDL mol file
				try
				{
					System.String atomCountString = line.Substring(0, (3) - (0)).Trim();
					System.String bondCountString = line.Substring(3, (6) - (3)).Trim();
					System.Int32.Parse(atomCountString);
					System.Int32.Parse(bondCountString);
					bool mdlFile = true;
					if (line.Length > 6)
					{
						System.String remainder = line.Substring(6).Trim();
						for (int i = 0; i < remainder.Length; ++i)
						{
							char c = remainder[i];
							if (!(System.Char.IsDigit(c) || System.Char.IsWhiteSpace(c)))
							{
								mdlFile = false;
							}
						}
					}
					// all tests succeeded, likely to be a MDL file
					if (mdlFile)
					{
						return true;
					}
				}
				catch (System.FormatException nfe)
				{
					// Integers not found on fourth line; therefore not a MDL file
				}
			}
			return false;
		}
Exemplo n.º 19
0
		public virtual bool matches(int lineNumber, System.String line)
		{
			if (line.StartsWith("HEADER") || line.StartsWith("HETATM ") || line.StartsWith("ATOM  "))
			{
				return true;
			}
			return false;
		}
Exemplo n.º 20
0
        /// <summary>Gets path information from a path spec. </summary>
        private PathSpec parsePathSpec(System.String spec)
        {
            PathSpec ps = new PathSpec(this);

            if (spec.StartsWith("."))
            {
                ps.find = true;
                spec = spec.Substring(1);
            }
            else
            {
                ps.find = false;
            }

            if (spec.Length == 0)
            {
                throw new HL7Exception("Invalid path (some path element is either empty or contains only a dot)");
            }
            SupportClass.Tokenizer tok = new SupportClass.Tokenizer(spec, "()", false);
            ps.pattern = tok.NextToken();
            if (tok.HasMoreTokens())
            {
                System.String repString = tok.NextToken();
                try
                {
                    ps.rep = System.Int32.Parse(repString);
                }
                catch (System.FormatException)
                {
                    throw new HL7Exception(repString + " is not a valid rep #", HL7Exception.APPLICATION_INTERNAL_ERROR);
                }
            }
            else
            {
                ps.rep = 0;
            }
            return ps;
        }
Exemplo n.º 21
0
		public virtual float ParseFloat(System.String value_Renamed)
		{
            try
            {
                return SupportClass.Single.Parse(value_Renamed);
            }
            catch (System.OverflowException)
            {
                return value_Renamed.StartsWith("-") ? float.PositiveInfinity : float.NegativeInfinity;
            }
		}
Exemplo n.º 22
0
			/* doc location == msgID & curPath together.  
			If we've encountered an element called "elementNam", then this tries 
			to determine what it is, based on what we already know about the document.
			returns true if we can make sense of this new element name given the
			position we're at (represented by msgID / curPath), 
			false if we can't (which probably means this should be a useless element). 
			returning true doesn't mean that we actually changed msgID or curPath, it
			might mean that we just passed through a segment group element OK.
			*/
			protected internal static bool tryToGrowDocLocationFromElementName(System.Text.StringBuilder msgID, NuGenDatumPath curPath, System.Collections.IDictionary segmentId2nextRepIdx, NuGenDatumPath lastDumpedPath, System.String elementName)
			{
				bool ok = false; // ok == can we make sense of this new element?
				// hmm ... where are we in the document: 
				if ((msgID.Length == 0) && (curPath.size() == 0))
				{
					// we're entering a message
					msgID.Replace(msgID.ToString(0, msgID.Length - 0), elementName, 0, msgID.Length - 0);
					segmentId2nextRepIdx.Clear();
					ok = true;
				}
				else if ((msgID.Length > 0) && (curPath.size() == 0))
				{
					// we're entering either a segment-group element (eg. <ADT_A01.PROCEDURE>)
					// or an actual segment element.
					if (!(elementName.StartsWith("" + msgID + '.')))
					{
						// must be an actual segment.
						curPath.add(elementName);
						
						if (segmentId2nextRepIdx.Contains(elementName))
							curPath.add(segmentId2nextRepIdx[elementName]);
						else
							curPath.add((System.Object) 0);
						
						segmentId2nextRepIdx[elementName] = (System.Int32) (((System.Int32) curPath.get_Renamed(curPath.size() - 1)) + 1);
					}
					ok = true;
				}
				else if ((msgID.Length > 0) && (curPath.size() > 0))
				{
					// we're entering a field or a component or a subcomponent.
					if (curPath.size() == 2)
					{
						// we're entering a field element
						// all fields should start with segment-ID + '.' 
						if (elementName.StartsWith("" + curPath.get_Renamed(0) + '.'))
						{
							try
							{
								int fieldIdxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));
								
								curPath.add((System.Object) fieldIdxFromElementName);
								
								// now add the repetition idx to curPath: 
								if ((lastDumpedPath.size() >= 4) && (((System.Int32) lastDumpedPath.get_Renamed(2)) == fieldIdxFromElementName))
								{
									// lastDumpedPath has a fieldIdx and a fieldRepIdx.
									curPath.add((System.Object) (((System.Int32) lastDumpedPath.get_Renamed(3)) + 1));
								}
								else
									curPath.add((System.Object) 0);
								
								ok = true;
							}
							catch (System.FormatException)
							{
							}
						} // else => this isn't a field -- must be useless.
					}
					else if ((curPath.size() == 4) || (curPath.size() == 5))
					{
						// we're entering a component or subcomponent element
						try
						{
							int idxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));
							curPath.add((System.Object) idxFromElementName);
							ok = true;
						}
						catch (System.FormatException)
						{
						}
					}
				}
				return ok;
			}
Exemplo n.º 23
0
        /// <summary> Returns a String representing the encoding of the given message, if
        /// the encoding is recognized.  For example if the given message appears
        /// to be encoded using HL7 2.x XML rules then "XML" would be returned.
        /// If the encoding is not recognized then null is returned.  That this
        /// method returns a specific encoding does not guarantee that the
        /// message is correctly encoded (e.g. well formed XML) - just that
        /// it is not encoded using any other encoding than the one returned.
        /// </summary>
        public override System.String getEncoding(System.String message)
        {
            System.String encoding = null;

            //quit if the string is too short
            if (message.Length < 4)
                return null;

            //see if it looks like this message is | encoded ...
            bool ok = true;

            //string should start with "MSH"
            if (!message.StartsWith("MSH"))
                return null;

            //4th character of each segment should be field delimiter
            char fourthChar = message[3];
            char[] fourthCharArray = fourthChar.ToString().ToCharArray();
            Tokenizer st = new Tokenizer(message, segDelim, false);
            while (st.HasMoreTokens)
            {
                System.String x = st.NextToken();
                if (x.Length > 0)
                {
                    if (System.Char.IsWhiteSpace(x[0]))
                        x = stripLeadingWhitespace(x);

                    if (x.Length >= 4)
                    {
                        string[] parts = x.Split(fourthCharArray,1);
                        if(parts.Length==0)
                            return null;

                        if(parts[0].Length==3 && x[3] !=fourthChar)
                        {
                            return null;
                        }
                        //CDC: If a segment is a non-standard segment and there are multiple, the segment name might by 4 char long
                        if(parts[0].Length != x.Length && parts[0].Length==4 && x[4] !=fourthChar)
                        {
                            return null;
                        }
                    }
                }
            }

            //should be at least 11 field delimiters (because MSH-12 is required)
            int nextFieldDelimLoc = 0;
            for (int i = 0; i < 11; i++)
            {
                //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
                nextFieldDelimLoc = message.IndexOf((System.Char) fourthChar, nextFieldDelimLoc + 1);
                if (nextFieldDelimLoc < 0)
                    return null;
            }

            if (ok)
                encoding = "VB";

            return encoding;
        }
		public virtual void  searchIndex(System.String dirName, System.String oldName)
		{
			//QueryParser parser = new QueryParser("contents", new WhitespaceAnalyzer());
			//Query query = parser.parse("handle:1");
			
			dirName = FullDir(dirName);
			
			Directory dir = FSDirectory.Open(new System.IO.FileInfo(dirName));
			IndexSearcher searcher = new IndexSearcher(dir);
			IndexReader reader = searcher.GetIndexReader();
			
			_TestUtil.CheckIndex(dir);
			
			for (int i = 0; i < 35; i++)
			{
				if (!reader.IsDeleted(i))
				{
					Document d = reader.Document(i);
					System.Collections.IList fields = d.GetFields();
					if (!oldName.StartsWith("19.") && !oldName.StartsWith("20.") && !oldName.StartsWith("21.") && !oldName.StartsWith("22."))
					{
						
						if (d.GetField("content3") == null)
						{
							Assert.AreEqual(5, fields.Count);
							Field f = (Field) d.GetField("id");
							Assert.AreEqual("" + i, f.StringValue());
							
							f = (Field) d.GetField("utf8");
							Assert.AreEqual("Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", f.StringValue());
							
							f = (Field) d.GetField("autf8");
							Assert.AreEqual("Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", f.StringValue());
							
							f = (Field) d.GetField("content2");
							Assert.AreEqual("here is more content with aaa aaa aaa", f.StringValue());
							
							f = (Field) d.GetField("fie\u2C77ld");
							Assert.AreEqual("field with non-ascii name", f.StringValue());
						}
					}
				}
				// Only ID 7 is deleted
				else
					Assert.AreEqual(7, i);
			}
			
			ScoreDoc[] hits = searcher.Search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
			
			// First document should be #21 since it's norm was
			// increased:
			Document d2 = searcher.Doc(hits[0].doc);
			Assert.AreEqual("21", d2.Get("id"), "didn't get the right document first");
			
			TestHits(hits, 34, searcher.GetIndexReader());
			
			if (!oldName.StartsWith("19.") && !oldName.StartsWith("20.") && !oldName.StartsWith("21.") && !oldName.StartsWith("22."))
			{
				// Test on indices >= 2.3
				hits = searcher.Search(new TermQuery(new Term("utf8", "\u0000")), null, 1000).scoreDocs;
				Assert.AreEqual(34, hits.Length);
				hits = searcher.Search(new TermQuery(new Term("utf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne")), null, 1000).scoreDocs;
				Assert.AreEqual(34, hits.Length);
				hits = searcher.Search(new TermQuery(new Term("utf8", "ab\ud917\udc17cd")), null, 1000).scoreDocs;
				Assert.AreEqual(34, hits.Length);
			}
			
			searcher.Close();
			dir.Close();
		}
Exemplo n.º 25
0
		/// <summary> Factory method for generating a query (similar to
		/// {@link #getWildcardQuery}). Called when parser parses an input term
		/// token that uses prefix notation; that is, contains a single '*' wildcard
		/// character as its last character. Since this is a special case
		/// of generic wildcard term, and such a query can be optimized easily,
		/// this usually results in a different query object.
		/// <p/>
		/// Depending on settings, a prefix term may be lower-cased
		/// automatically. It will not go through the default Analyzer,
		/// however, since normal Analyzers are unlikely to work properly
		/// with wildcard templates.
		/// <p/>
		/// Can be overridden by extending classes, to provide custom handling for
		/// wild card queries, which may be necessary due to missing analyzer calls.
		/// 
		/// </summary>
		/// <param name="field">Name of the field query will use.
		/// </param>
		/// <param name="termStr">Term token to use for building term for the query
		/// (<b>without</b> trailing '*' character!)
		/// 
		/// </param>
		/// <returns> Resulting {@link Query} built for the term
		/// </returns>
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		public /*protected internal*/ virtual Query GetPrefixQuery(System.String field, System.String termStr)
		{
			if (!allowLeadingWildcard && termStr.StartsWith("*"))
				throw new ParseException("'*' not allowed as first character in PrefixQuery");
			if (lowercaseExpandedTerms)
			{
				termStr = termStr.ToLower();
			}
			Term t = new Term(field, termStr);
			return NewPrefixQuery(t);
		}
Exemplo n.º 26
0
        public override void startElement(System.String uri, System.String local, System.String raw, SaxAttributesSupport atts)
        {
            xpath.push(local);
            //if (debug)
            //    logger.debug("<", raw, "> -> ", xpath);
            // Detect CML modules, like CRML and CCML
            if (local.StartsWith("reaction"))
            {
                // e.g. reactionList, reaction -> CRML module
                //logger.info("Detected CRML module");
                conv = new CMLReactionModule(conv);
                conventionStack.push(conventionStack.current());
            }
            else
            {
                // assume CML Core

                // Detect conventions
                System.String convName = "";
                for (int i = 0; i < atts.GetLength(); i++)
                {
                    if (atts.GetFullName(i).Equals("convention"))
                    {
                        convName = atts.GetValue(i);
                    }
                }
                if (convName.Length > 0)
                {
                    if (convName.Equals(conventionStack.current()))
                    {
                        //logger.debug("Same convention as parent");
                    }
                    else
                    {
                        //logger.info("New Convention: ", convName);
                        if (convName.Equals("CML"))
                        {
                            /* Don't reset the convention handler to CMLCore,
                            becuase all handlers should extend this handler,
                            and use it for any content other then specifically
                            put into the specific convention */
                        }
                        else if (convName.Equals("PDB"))
                        {
                            conv = new PDBConvention(conv);
                        }
                        else if (convName.Equals("PMP"))
                        {
                            conv = new PMPConvention(conv);
                        }
                        else if (convName.Equals("MDLMol"))
                        {
                            //if (debug)
                            //    logger.debug("MDLMolConvention instantiated...");
                            conv = new MDLMolConvention(conv);
                        }
                        else if (convName.Equals("JMOL-ANIMATION"))
                        {
                            conv = new JMOLANIMATIONConvention(conv);
                        }
                        else if (userConventions.ContainsKey(convName))
                        {
                            //unknown convention. userConvention?
                            ICMLConvention newconv = (ICMLConvention)userConventions[convName];
                            newconv.inherit(conv);
                            conv = newconv;
                        }
                        else
                        {
                            //logger.warn("Detected unknown convention: ", convName);
                        }
                    }
                    conventionStack.push(convName);
                }
                else
                {
                    // no convention set/reset: take convention of parent
                    conventionStack.push(conventionStack.current());
                }
            }
            //if (debug)
            //    logger.debug("ConventionStack: ", conventionStack);
            conv.startElement(xpath, uri, local, raw, atts);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Converts a System.String number to long.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static long ToInt64(System.String s)
        {
            long number = 0;
            long factor;

            // handle negative number
            if (s.StartsWith("-"))
            {
                s = s.Substring(1);
                factor = -1;
            }
            else
            {
                factor = 1;
            }

            // generate number
            for (int i = s.Length - 1; i > -1; i--)
            {
                int n = digits.IndexOf(s[i]);

                // not supporting fractional or scientific notations
                if (n < 0)
                    throw new System.ArgumentException("Invalid or unsupported character in number: " + s[i]);

                number += (n * factor);
                factor *= 36;
            }

            return number;
        }
Exemplo n.º 28
0
		public virtual bool matches(int lineNumber, System.String line)
		{
			if (line.StartsWith("ZERR ") || line.StartsWith("TITL "))
			{
				return true;
			}
			return false;
		}
Exemplo n.º 29
0
		/// <summary> C: The SWD generation for fdb is... flaky, especially the way to figure out
		/// the bitmap category based on debug module names. DebugModule and DebugScript
		/// must be set with a flag indicating whether they are classes, frame actions,
		/// etc, etc, etc.
		/// 
		/// R: I don't particularly like it either and would prefer it if this stuff
		/// lived on the fdb side, not in here.
		/// </summary>
		private bool isFrameworkClass(System.String name)
		{
			bool isIt = (name.StartsWith("mx.") && name.IndexOf(":") != - 1 && name.EndsWith(".as")) || (name.IndexOf("/mx/") > - 1);
			
			return isIt;
		}
Exemplo n.º 30
0
		/// <summary> Converts a Unicode string to ASCII using the procedure in RFC3490
		/// section 4.1. Unassigned characters are not allowed and STD3 ASCII
		/// rules are enforced.
		/// *
		/// </summary>
		/// <param name="input">Unicode string.
		/// </param>
		/// <param name="allowUnassigned">Unassigned characters, allowed or not?
		/// </param>
		/// <param name="useSTD3ASCIIRules">STD3 ASCII rules, enforced or not?
		/// </param>
		/// <returns> Encoded string.
		/// 
		/// </returns>
		public static System.String toASCII(System.String input, bool allowUnassigned, bool useSTD3ASCIIRules)
		{
			// Step 1: Check if the string contains code points outside
			//         the ASCII range 0..0x7c.
			
			bool nonASCII = false;
			
			for (int i = 0; i < input.Length; i++)
			{
				int c = input[i];
				if (c > 0x7f)
				{
					nonASCII = true;
					break;
				}
			}
			
			// Step 2: Perform the nameprep operation.
			
			if (nonASCII)
			{
				try
				{
					input = Stringprep.nameprep(input, allowUnassigned);
				}
				catch (StringprepException e)
				{
					// TODO 
					throw new IDNAException(e);
				}
			}
			
			// Step 3: - Verify the absence of non-LDH ASCII code points
			//    (char) 0..0x2c, 0x2e..0x2f, 0x3a..0x40, 0x5b..0x60,
			//    (char) 0x7b..0x7f
			//         - Verify the absence of leading and trailing
			//           hyphen-minus
			
			if (useSTD3ASCIIRules)
			{
				for (int i = 0; i < input.Length; i++)
				{
					int c = input[i];
					if ((c <= 0x2c) || (c >= 0x2e && c <= 0x2f) || (c >= 0x3a && c <= 0x40) || (c >= 0x5b && c <= 0x60) || (c >= 0x7b && c <= 0x7f))
					{
						throw new IDNAException(IDNAException.CONTAINS_NON_LDH);
					}
				}
				
				if (input.StartsWith("-") || input.EndsWith("-"))
				{
					throw new IDNAException(IDNAException.CONTAINS_HYPHEN);
				}
			}
			
			// Step 4: If all code points are inside 0..0x7f, skip to step 8
			
			nonASCII = false;
			
			for (int i = 0; i < input.Length; i++)
			{
				int c = input[i];
				if (c > 0x7f)
				{
					nonASCII = true;
					break;
				}
			}
			
			System.String output = input;
			
			if (nonASCII)
			{
				
				// Step 5: Verify that the sequence does not begin with the ACE prefix.
				
				if (input.StartsWith(ACE_PREFIX))
				{
					throw new IDNAException(IDNAException.CONTAINS_ACE_PREFIX);
				}
				
				// Step 6: Punycode
				
				try
				{
					output = Punycode.encode(input);
				}
				catch (PunycodeException e)
				{
					// TODO
					throw new IDNAException(e);
				}
				
				// Step 7: Prepend the ACE prefix.
				
				output = ACE_PREFIX + output;
			}
			
			// Step 8: Check that the length is inside 1..63.
			
			if (output.Length < 1 || output.Length > 63)
			{
				throw new IDNAException(IDNAException.TOO_LONG);
			}
			
			return output;
		}