Exemplo n.º 1
0
		/// <summary> Splits the given composite string into an array of components using the given
		/// delimiter.
		/// </summary>
		public static String[] Split(String composite, String delim)
		{
			ArrayList components = new ArrayList();

			//defend against evil nulls
			if (composite == null)
				composite = "";
			if (delim == null)
				delim = "";

			SupportClass.Tokenizer tok = new SupportClass.Tokenizer(composite, delim, true);
			bool previousTokenWasDelim = true;
			while (tok.HasMoreTokens())
			{
				String thisTok = tok.NextToken();
				if (thisTok.Equals(delim))
				{
					if (previousTokenWasDelim)
						components.Add(null);
					previousTokenWasDelim = true;
				}
				else
				{
					components.Add(thisTok);
					previousTokenWasDelim = false;
				}
			}

			String[] ret = new String[components.Count];
			for (int i = 0; i < components.Count; i++)
			{
				ret[i] = ((String) components[i]);
			}

			return ret;
		}
Exemplo n.º 2
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 String GetEncoding(String message)
		{
			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, Convert.ToString(segDelim), false);
			while (st.HasMoreTokens())
			{
				String x = st.NextToken();
				if (x.Length > 0)
				{
					if (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((Char) fourthChar, nextFieldDelimLoc + 1);
				if (nextFieldDelimLoc < 0)
					return null;
			}

			if (ok)
				encoding = "VB";

			return encoding;
		}