internal static PartialParseResult<ExtensionSubtagCollection> Parse(TokenEnumerator tokens) { var subtagResult = ExtensionSubtag.Parse(tokens); if (subtagResult.NothingToParse) return PartialParseResult<ExtensionSubtagCollection>.Empty; if (subtagResult.ErrorOccured) return PartialParseResult<ExtensionSubtagCollection>.Error; var resultCollection = new List<ExtensionSubtag>(); var usedSingletons = new bool[128]; while (true) { var subtag = subtagResult.Result; if (usedSingletons[subtag.Singleton]) return PartialParseResult<ExtensionSubtagCollection>.Error; usedSingletons[subtag.Singleton] = true; resultCollection.Add(subtag); subtagResult = ExtensionSubtag.Parse(tokens); if (subtagResult.NothingToParse) return PartialParseResult<ExtensionSubtagCollection>.Success( new ExtensionSubtagCollection(resultCollection)); if (subtagResult.ErrorOccured) return PartialParseResult<ExtensionSubtagCollection>.Error; } }
internal static PartialParseResult <PrivateUseSubtags> Parse(TokenEnumerator tokens) { if (!tokens.TokenIs(Singleton)) { return(PartialParseResult <PrivateUseSubtags> .Empty); } tokens.ToNextToken(); var subtags = new List <string>(); while (tokens.CurrentTokenAvailable) { if (!isValidSubtag(tokens.Token)) { return(PartialParseResult <PrivateUseSubtags> .Error); } subtags.Add(tokens.Token); tokens.ToNextToken(); } if (subtags.Count == 0) { return(PartialParseResult <PrivateUseSubtags> .Error); } return(PartialParseResult <PrivateUseSubtags> .Success(new PrivateUseSubtags(subtags))); }
internal static PartialParseResult <ExtensionSubtag> Parse(TokenEnumerator tokens) { // Get the singleton if (!tokens.CurrentTokenAvailable) { return(PartialParseResult <ExtensionSubtag> .Empty); } if (tokens.Token.Length != 1 || tokens.TokenIs(PrivateUseSubtags.Singleton)) { return(PartialParseResult <ExtensionSubtag> .Empty); } var singleton = tokens.Token[0]; if (!isAsciiLetterOrDigit(singleton)) { return(PartialParseResult <ExtensionSubtag> .Error); } if (!tokens.NextTokenAvailable) { return(PartialParseResult <ExtensionSubtag> .Error); } var sequence = new List <string>(); tokens.ToNextToken(); if (!isValidElement(tokens.Token)) { return(PartialParseResult <ExtensionSubtag> .Error); } sequence.Add(tokens.Token); // Get remaining elements tokens.ToNextToken(); while (tokens.CurrentTokenAvailable) { if (tokens.Token.Length == 1) // next extension subtag or private use { break; } if (!isValidElement(tokens.Token)) { return(PartialParseResult <ExtensionSubtag> .Error); } sequence.Add(tokens.Token); tokens.ToNextToken(); } return(PartialParseResult <ExtensionSubtag> .Success(new ExtensionSubtag(singleton, sequence))); }