public static SchemaRegex Lookup(string pattern) { if (pattern == null) { return(null); } lock (cache) { SchemaRegex regex = cache[pattern]; if (regex != null) { return(regex); } cache[pattern] = regex = new SchemaRegex(pattern); return(regex); } }
private bool ValidateString(Subschema schema, string value) { bool finalResult = true; for (var mask = schema.Flags & SchemaFlags.StringProperties; mask != 0; mask = (SchemaFlags)RemoveLowestBit((long)mask)) { Keyword keyword = (Keyword)IndexOfLowestBit((long)mask); bool? result = true; switch (keyword) { case Keyword.MinLength: StringInfo si; result = value.Length >= schema.MinLength; if (result == true && Strict) { si = StringInfo; si.String = value; result = si.LengthInTextElements >= schema.MinLength; } break; case Keyword.MaxLength: result = value.Length <= schema.MaxLength; if (result == false && Strict) { si = StringInfo; si.String = value; result = si.LengthInTextElements <= schema.MaxLength; } break; case Keyword.Pattern: SchemaRegex pattern = schema.Pattern; var resultType = pattern.Matches(value); if (resultType != SchemaRegexSuccess.Success) { if (resultType == SchemaRegexSuccess.TimedOut) { SchemaPointer.Push(Keyword.Pattern); ReportError(ErrorType.TimeLimit, schema, value); SchemaPointer.Pop(); return(false); } finalResult = false; if (ReportError(keyword, schema, value, pattern.Pattern)) { return(false); } } continue; case Keyword.Format: result = Formats.IsValueOfFormat(value, schema.Format); break; } if (result == false) { finalResult = false; if (ReportError(keyword, schema, value)) { return(false); } } } return(finalResult); }