/// <summary> /// Проверка, что заданная коллекция юнитов содержит только одно целое число /// </summary> /// <param name="units">юниты</param> /// <returns>результат проверки</returns> private bool IsInteger(IEnumerable <UnitTextBase> units) { bool result = true; bool isContainNumber = false; foreach (var unit in units) { if (!unit.IsEntity) { continue; } var entity = (Entity)unit; if (entity.Type.EntityType.HasValue && (entity.Type.EntityType.Value == EntityType.Numeric)) { if (isContainNumber) { result = false; } else { isContainNumber = true; result = entity.Value.IndexOf('.') < 0; } } else if (RegexEntityType.IsNumberEntityType(entity.Type.CustomType)) { result = false; } if (!result) { break; } } return(result); }
/// <summary> /// Кодирование сущности /// </summary> /// <param name="unmarked">сущности</param> /// <returns>закодированное значение</returns> private static string CodeEntity(Entity entity) { if (entity.Type.CustomType == RegexEntityType.Fraction) { return("fraction"); } else if (RegexEntityType.IsNumberEntityType(entity.Type.CustomType)) { return("numeric"); } else { return("entity"); } }
/// <summary> /// Проверка, что заданная сущность - число /// </summary> /// <param name="entity">сущность</param> /// <returns>результат проверки</returns> public static bool IsNumber(this Entity entity) { return(entity.IsType(EntityType.Numeric) || RegexEntityType.IsNumberEntityType(entity.Type.CustomType)); }