// Group: Information Functions // __________________________________________________________________________ /* Function: KeywordDefinition * Returns the <KeywordDefinition> which matches the passed name and language ID, or null if none. If language ID is * zero it will only return language agnostic definitions, whereas if it has a value it will also search the language-specific * definitions and favor those if there are both. */ public KeywordDefinition KeywordDefinition(string keyword, int languageID) { KeywordDefinition singleDefinition = singleDefinitionKeywords[keyword]; if (singleDefinition != null) { if (singleDefinition.IsLanguageAgnostic || singleDefinition.LanguageID == languageID) { return(singleDefinition); } else { return(null); } } List <KeywordDefinition> definitionList = multiDefinitionKeywords[keyword]; if (definitionList != null) { KeywordDefinition agnosticDefinition = null; foreach (var definition in definitionList) { if (definition.IsLanguageSpecific) { if (languageID == definition.LanguageID) { return(definition); } } else // definition.IsLanguageAgnostic { if (languageID == 0) { return(definition); } else { agnosticDefinition = definition; } } } return(agnosticDefinition); // will be null if one wasn't found, which is what we want } return(null); }
/* Function: AddKeywordDefinition * Adds a keyword definition to the configuration. If a definition already exists for the keyword but with a different * language ID, both definitions will be stored. If a definition already exists with the same language ID, this one will * overwrite the previous one. */ public void AddKeywordDefinition(KeywordDefinition keywordDefinition) { // First check the multi-definition list List <KeywordDefinition> multiDefinitionList = multiDefinitionKeywords[keywordDefinition.Keyword]; if (multiDefinitionList != null) { // If it's already in the list with this language ID, overwrite it for (int i = 0; i < multiDefinitionList.Count; i++) { if (multiDefinitionList[i].LanguageID == keywordDefinition.LanguageID) { multiDefinitionList[i] = keywordDefinition; return; } } // If it's not, add it multiDefinitionList.Add(keywordDefinition); return; } // Now check the single definition list KeywordDefinition existingDefinition = singleDefinitionKeywords[keywordDefinition.Keyword]; if (existingDefinition != null) { // If it has the same language ID, overwrite it if (existingDefinition.LanguageID == keywordDefinition.LanguageID) { singleDefinitionKeywords[keywordDefinition.Keyword] = keywordDefinition; return; } // Otherwise, transfer both definitions to the multi-definition list multiDefinitionList = new List <KeywordDefinition>(2); multiDefinitionList.Add(existingDefinition); multiDefinitionList.Add(keywordDefinition); multiDefinitionKeywords.Add(keywordDefinition.Keyword, multiDefinitionList); singleDefinitionKeywords.Remove(keywordDefinition.Keyword); return; } // Otherwise it wasn't defined at all, so add it to the single definition list singleDefinitionKeywords.Add(keywordDefinition.Keyword, keywordDefinition); }
/* Function: MergeKeywordsInto_Stage2 * Merges the keywords from the <ConfigFiles.TextFile> into the <Config>, returning whether it was successful. It * assumes all <ConfigFiles.TextCommentTypes> in textConfig have corresponding <CommentTypes> in outputConfig. * Any errors will be added to errorList, such as having a language-specific keyword that doesn't match a name in * <Languages.Manager>. */ protected bool MergeKeywordsInto_Stage2(ref Config outputConfig, ConfigFiles.TextFile textConfig, StringSet ignoredKeywords, Errors.ErrorList errorList) { bool success = true; if (textConfig.HasCommentTypes) { foreach (var commentType in textConfig.CommentTypes) { int commentTypeID = outputConfig.CommentTypeFromName(commentType.Name).ID; #if DEBUG if (commentTypeID == 0) { throw new InvalidOperationException(); } #endif if (commentType.HasKeywordGroups) { foreach (var keywordGroup in commentType.KeywordGroups) { int languageID = 0; if (keywordGroup.IsLanguageSpecific) { var language = EngineInstance.Languages.FromName(keywordGroup.LanguageName); if (language == null) { errorList.Add( Locale.Get("NaturalDocs.Engine", "Comments.txt.UnrecognizedKeywordLanguage(name)", keywordGroup.LanguageName), keywordGroup.PropertyLocation ); success = false; } else { languageID = language.ID; } } foreach (var keywordDefinition in keywordGroup.KeywordDefinitions) { if (!ignoredKeywords.Contains(keywordDefinition.Keyword)) { var outputKeywordDefinition = new KeywordDefinition(keywordDefinition.Keyword); outputKeywordDefinition.CommentTypeID = commentTypeID; if (languageID != 0) { outputKeywordDefinition.LanguageID = languageID; } // AddKeywordDefinition will handle overwriting definitions with the same keyword and language outputConfig.AddKeywordDefinition(outputKeywordDefinition); } if (keywordDefinition.HasPlural && !ignoredKeywords.Contains(keywordDefinition.Plural)) { var outputKeywordDefinition = new KeywordDefinition(keywordDefinition.Plural); outputKeywordDefinition.CommentTypeID = commentTypeID; outputKeywordDefinition.Plural = true; if (languageID != 0) { outputKeywordDefinition.LanguageID = languageID; } outputConfig.AddKeywordDefinition(outputKeywordDefinition); } } } } } } return(success); }