1 //---------------------------------------------------------------------
2 // <copyright file="CqlWriter.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 using System.Text.RegularExpressions;
12 using System.Data.Common.Utils;
13 using System.Data.Mapping.ViewGeneration.Utils;
14 using System.Data.Metadata.Edm;
16 namespace System.Data.Mapping.ViewGeneration.CqlGeneration
19 // This class contains helper methods needed for generating Cql
20 internal static class CqlWriter
24 private static readonly Regex s_wordIdentifierRegex = new Regex(@"^[_A-Za-z]\w*$", RegexOptions.ECMAScript | RegexOptions.Compiled);
27 #region Helper Methods
28 // effects: Given a block name and a field in it -- returns a string
29 // of form "blockName.field". Does not perform any escaping
30 internal static string GetQualifiedName(string blockName, string field)
32 string result = StringUtil.FormatInvariant("{0}.{1}", blockName, field);
36 // effects: Modifies builder to contain an escaped version of type's name as "[namespace.typename]"
37 internal static void AppendEscapedTypeName(StringBuilder builder, EdmType type)
39 AppendEscapedName(builder, GetQualifiedName(type.NamespaceName, type.Name));
42 // effects: Modifies builder to contain an escaped version of "name1.name2" as "[name1].[name2]"
43 internal static void AppendEscapedQualifiedName(StringBuilder builder, string name1, string name2)
45 AppendEscapedName(builder, name1);
47 AppendEscapedName(builder, name2);
50 // effects: Modifies builder to contain an escaped version of "name"
51 internal static void AppendEscapedName(StringBuilder builder, string name)
53 if (s_wordIdentifierRegex.IsMatch(name) && false == ExternalCalls.IsReservedKeyword(name))
55 // We do not need to escape the name if it is a simple name and it is not a keyword
60 string newName = name.Replace("]", "]]");