using System;
using System.Globalization;

namespace OmniBeanEB.Library
{
	[SmallBasicType]
	public class Text
	{
		public static EBPrimitive Append(EBPrimitive text1, EBPrimitive text2)
		{
			return text1 + text2;
		}

		public static EBPrimitive GetLength(EBPrimitive ptext)
		{
			string text = ptext.ToString();
			if (text == "")
			{
				return 0;
			}
			return text.Length;
		}

		public static EBPrimitive IsSubText(EBPrimitive _text, EBPrimitive _subText)
		{
			string text = _text.ToString();
			string subText = _subText.ToString();
			if (text == "" || subText == "")
			{
				return false;
			}
			return text.Contains(subText);
		}

		public static EBPrimitive EndsWith(EBPrimitive _text, EBPrimitive _subText)
		{
			string text = _text.ToString();
			string subText = _subText.ToString();
			if (text == "" || subText == "")
			{
				return false;
			}
			return text.EndsWith(subText, StringComparison.CurrentCulture);
		}

		public static EBPrimitive StartsWith(EBPrimitive _text, EBPrimitive _subText)
		{
			string text = _text.ToString();
			string subText = _subText.ToString();
			if (text == "" || subText == "")
			{
				return false;
			}
			return text.StartsWith(subText, StringComparison.CurrentCulture);
		}

		public static EBPrimitive GetSubText(EBPrimitive _text, EBPrimitive _start, EBPrimitive _length)
		{
			string text = _text.ToString();
			int start = _start;
			int length = _length;
			if (text == "" || start > text.Length || start < 1 || start.ToString() == "" || length.ToString() == "")
			{
				return "";
			}
			if (start + length <= text.Length)
			{
				return text.Substring(start - 1, length);
			}
			return text.Substring(start - 1);
		}

		public static EBPrimitive GetSubTextToEnd(EBPrimitive _text, EBPrimitive _start)
		{
			string text = _text.ToString();
			int start = _start;
			if (text == "" || start > text.Length || start < 1 || start.ToString() == "")
			{
				return "";
			}
			return text.Substring(start - 1);
		}

		public static EBPrimitive GetIndexOf(EBPrimitive _text, EBPrimitive _subText)
		{
			string text = _text;
			string subText = _subText;
			if (text=="")
			{
				return 0;
			}
			if (subText=="")
			{
				return 0;
			}
			return text.IndexOf(subText) + 1;
		}

		public static EBPrimitive ConvertToLowerCase(EBPrimitive _text)
		{
			string text = _text;
			if (text=="")
			{
				return text;
			}
			return text.ToLower(CultureInfo.CurrentUICulture);
		}

		public static EBPrimitive ConvertToUpperCase(EBPrimitive _text)
		{
			string text = _text.ToString();
			if (text=="")
			{
				return text;
			}
			return text.ToUpper(CultureInfo.InvariantCulture);
		}

		public static EBPrimitive GetCharacter(EBPrimitive characterCode)
		{
			int num = characterCode;
			return ((char)num).ToString();
		}

		public static EBPrimitive GetCharacterCode(EBPrimitive character)
		{
			if (character.IsEmpty)
			{
				return 0;
			}
			return (int)character[0];
		}
	}
}
