Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
  3. * Copyright (C) 2009, Constantine Plotnikov <constantine.plotnikov@gmail.com>
  4. * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
  5. * Copyright (C) 2008-2010, Google Inc.
  6. * Copyright (C) 2009, Google, Inc.
  7. * Copyright (C) 2009, JetBrains s.r.o.
  8. * Copyright (C) 2007-2008, Robin Rosenberg <robin.rosenberg@dewire.com>
  9. * Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org>
  10. * Copyright (C) 2008, Thad Hughes <thadh@thad.corp.google.com>
  11. * and other copyright owners as documented in the project's IP log.
  12. *
  13. * This program and the accompanying materials are made available
  14. * under the terms of the Eclipse Distribution License v1.0 which
  15. * accompanies this distribution, is reproduced below, and is
  16. * available at http://www.eclipse.org/org/documents/edl-v10.php
  17. *
  18. * All rights reserved.
  19. *
  20. * Redistribution and use in source and binary forms, with or
  21. * without modification, are permitted provided that the following
  22. * conditions are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. *
  27. * - Redistributions in binary form must reproduce the above
  28. * copyright notice, this list of conditions and the following
  29. * disclaimer in the documentation and/or other materials provided
  30. * with the distribution.
  31. *
  32. * - Neither the name of the Eclipse Foundation, Inc. nor the
  33. * names of its contributors may be used to endorse or promote
  34. * products derived from this software without specific prior
  35. * written permission.
  36. *
  37. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  38. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  39. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  40. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  41. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  44. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  45. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  46. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  47. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  48. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  49. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50. */
  51. package org.eclipse.jgit.lib;
  52. import org.eclipse.jgit.util.StringUtils;
  53. /** A line in a Git {@link Config} file. */
  54. class ConfigLine {
  55. /** The text content before entry. */
  56. String prefix;
  57. /** The section name for the entry. */
  58. String section;
  59. /** Subsection name. */
  60. String subsection;
  61. /** The key name. */
  62. String name;
  63. /** The value. */
  64. String value;
  65. /** The text content after entry. */
  66. String suffix;
  67. /** The source from which this line was included from. */
  68. String includedFrom;
  69. ConfigLine forValue(String newValue) {
  70. final ConfigLine e = new ConfigLine();
  71. e.prefix = prefix;
  72. e.section = section;
  73. e.subsection = subsection;
  74. e.name = name;
  75. e.value = newValue;
  76. e.suffix = suffix;
  77. e.includedFrom = includedFrom;
  78. return e;
  79. }
  80. boolean match(final String aSection, final String aSubsection,
  81. final String aKey) {
  82. return eqIgnoreCase(section, aSection)
  83. && eqSameCase(subsection, aSubsection)
  84. && eqIgnoreCase(name, aKey);
  85. }
  86. boolean match(String aSection, String aSubsection) {
  87. return eqIgnoreCase(section, aSection)
  88. && eqSameCase(subsection, aSubsection);
  89. }
  90. private static boolean eqIgnoreCase(String a, String b) {
  91. if (a == null && b == null)
  92. return true;
  93. if (a == null || b == null)
  94. return false;
  95. return StringUtils.equalsIgnoreCase(a, b);
  96. }
  97. private static boolean eqSameCase(String a, String b) {
  98. if (a == null && b == null)
  99. return true;
  100. if (a == null || b == null)
  101. return false;
  102. return a.equals(b);
  103. }
  104. /** {@inheritDoc} */
  105. @SuppressWarnings("nls")
  106. @Override
  107. public String toString() {
  108. if (section == null)
  109. return "<empty>";
  110. StringBuilder b = new StringBuilder(section);
  111. if (subsection != null)
  112. b.append(".").append(subsection);
  113. if (name != null)
  114. b.append(".").append(name);
  115. if (value != null)
  116. b.append("=").append(value);
  117. return b.toString();
  118. }
  119. }