PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Data.Linq/src/DbLinq/Util/QuotesHelper.cs

https://bitbucket.org/steenlund/mono-2.6.7-for-amiga
C# | 70 lines | 34 code | 3 blank | 33 comment | 9 complexity | c698923cda81fddc751bfadc1fabd978 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, LGPL-2.1
  1. #region MIT license
  2. //
  3. // MIT license
  4. //
  5. // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. //
  25. #endregion
  26. using System;
  27. using System.Collections.Generic;
  28. using System.Data;
  29. using System.Linq;
  30. using System.Text;
  31. using System.Text.RegularExpressions;
  32. namespace DbLinq.Util
  33. {
  34. /// <summary>
  35. /// maintainer: Anton Andreev
  36. /// </summary>
  37. internal static class QuotesHelper
  38. {
  39. public static string AddQuotesToSequence(string idColName, string sequenceName)
  40. {
  41. if (idColName != idColName.ToLower() && !sequenceName.StartsWith("\""))//toncho11: quotes are added due to issue http://code.google.com/p/dblinq2007/issues/detail?id=27}
  42. {
  43. sequenceName = "\"" + sequenceName.Replace(".", "\".\"") + "\"";
  44. }
  45. return sequenceName;
  46. }
  47. /// <summary>
  48. /// Enquotes a given string, if not already enquoted
  49. /// </summary>
  50. /// <param name="name">The string to enquote</param>
  51. /// <param name="startQuote">The start quote</param>
  52. /// <param name="endQuote">The end quote</param>
  53. /// <returns></returns>
  54. public static string Enquote(string name, char startQuote, char endQuote)
  55. {
  56. if (name.Length > 0 && name[0] != startQuote)
  57. name = startQuote + name;
  58. if (name.Length > 0 && name[name.Length - 1] != endQuote)
  59. name = name + endQuote;
  60. return name;
  61. }
  62. public static string Enquote(string name, char quote)
  63. {
  64. return Enquote(name, quote, quote);
  65. }
  66. }
  67. }