Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sp"></param>
        /// <returns></returns>
        public static string ToStringData(this StringWithPosition sp)
        {
            string result = string.Empty;

            if (sp != null)
            {
                result = sp.StringData;
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 转换为位置,如果为null,则返回-1
        /// </summary>
        /// <param name="sp"></param>
        /// <returns></returns>
        public static int ToPosition(this StringWithPosition sp)
        {
            int result = -1;

            if (sp != null)
            {
                result = sp.Position;
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// StringWithPosition的StringData是否等于某个字符串。如果sp为null,则相当于比较空串
        /// </summary>
        /// <param name="sp"></param>
        /// <param name="actual"></param>
        /// <param name="ignoreCase"></param>
        /// <returns></returns>
        public static bool AreEqual(this StringWithPosition sp, string actual, bool ignoreCase = false)
        {
            bool result = false;

            if (sp != null)
            {
                result = string.Compare(sp.StringData, actual, ignoreCase) == 0;
            }
            else
            {
                result = actual.IsNullOrEmpty();
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="identifiers"></param>
        /// <param name="maxPosition"></param>
        /// <returns></returns>
        public static StringWithPosition FindPreviousIdentifier(this IList <StringWithPosition> identifiers, int maxPosition = int.MaxValue)
        {
            StringWithPosition result = null;

            if (identifiers != null)
            {
                for (int i = identifiers.Count - 1; i >= 0; i--)
                {
                    StringWithPosition identifier = identifiers[i];

                    if (identifier.Position < maxPosition)
                    {
                        result = identifier;
                        break;
                    }
                }
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sp"></param>
        /// <param name="actual"></param>
        /// <param name="ignoreCase"></param>
        /// <returns></returns>
        public static bool Include(this StringWithPosition sp, string actual, bool ignoreCase = false)
        {
            bool result = false;

            if (sp != null && sp.StringData != null)
            {
                StringComparison sc = StringComparison.Ordinal;

                if (ignoreCase)
                {
                    sc = StringComparison.OrdinalIgnoreCase;
                }

                result = sp.StringData.IndexOf(actual, sc) >= 0;
            }
            else
            {
                result = actual.IsNullOrEmpty();
            }

            return(result);
        }
Пример #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sp"></param>
 /// <param name="actual"></param>
 /// <param name="ignoreCase"></param>
 /// <returns></returns>
 public static bool AreNotEqual(this StringWithPosition sp, string actual, bool ignoreCase = false)
 {
     return(AreEqual(sp, actual, ignoreCase) == false);
 }