// ******************************************************************************************************************************** /// <summary> /// Finds a string literal in a source code file with respect to escaping rules /// of the language. /// </summary> /// <param name="fileName">The name of the file to search in.</param> /// <param name="fileContent">The text content of the file.</param> /// <param name="literal">The string literal to find.</param> /// <param name="startOffset">The position to start searching at.</param> /// <param name="code">Receives the unquoted program code that represents the specified string literal in the language this file is written in.</param> /// <returns>The next index where the specified string literal appears, or -1 if there is no match or the language cannot be determined.</returns> public static int FindStringLiteral(string fileName, string fileContent, string literal, int startOffset, out string code) { ICSharpCode.SharpDevelop.Dom.LanguageProperties lp = NRefactoryResourceResolver.GetLanguagePropertiesForFile(fileName); if (lp != null && lp.CodeGenerator != null) { code = lp.CodeGenerator.GenerateCode(new PrimitiveExpression(literal, literal), String.Empty); if (!String.IsNullOrEmpty(code)) { // Unquote the string if possible. if (code.StartsWith("\"") || code.StartsWith("'")) { code = code.Substring(1); } if (code.EndsWith("\"") || code.EndsWith("'")) { code = code.Remove(code.Length - 1); } return(fileContent.IndexOf(code, startOffset, StringComparison.OrdinalIgnoreCase)); } } code = null; return(-1); }
public static void InitializeResolvers() { NRefactoryResourceResolver.SetResourceResolversListUnitTestOnly( new INRefactoryResourceResolver[] { new BclNRefactoryResourceResolver(), new ICSharpCodeCoreNRefactoryResourceResolver() }); ResourceResolverService.SetResourceResolversListUnitTestOnly( new IResourceResolver[] { new NRefactoryResourceResolver(), new ICSharpCodeCoreResourceResolver() }); }