Browse Source

PersonIdent: Make appendSanitized public

Change-Id: I337c90fff3c013819a42a7622ac6bacc72828c07
stable-4.4
Dave Borowitz 9 years ago committed by Terry Parker
parent
commit
c9b00288fd
  1. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java

@ -132,4 +132,11 @@ public class T0001_PersonIdentTest {
assertTrue(externalString.startsWith(" <>")); assertTrue(externalString.startsWith(" <>"));
} }
@Test
public void testAppendSanitized() {
StringBuilder r = new StringBuilder();
PersonIdent.appendSanitized(r, " Baz>\n\u1234<Quux ");
assertEquals("Baz\u1234Quux", r.toString());
}
} }

7
org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java

@ -122,8 +122,9 @@ public class PersonIdent implements Serializable {
* string builder to append to. * string builder to append to.
* @param str * @param str
* input string. * input string.
* @since 4.4
*/ */
private static void appendSanitized(StringBuilder r, String str) { public static void appendSanitized(StringBuilder r, String str) {
// Trim any whitespace less than \u0020 as in String#trim(). // Trim any whitespace less than \u0020 as in String#trim().
int i = 0; int i = 0;
while (i < str.length() && str.charAt(i) <= ' ') { while (i < str.length() && str.charAt(i) <= ' ') {
@ -318,6 +319,9 @@ public class PersonIdent implements Serializable {
return tzOffset; return tzOffset;
} }
/**
* Hashcode is based only on the email address and timestamp.
*/
public int hashCode() { public int hashCode() {
int hc = getEmailAddress().hashCode(); int hc = getEmailAddress().hashCode();
hc *= 31; hc *= 31;
@ -370,3 +374,4 @@ public class PersonIdent implements Serializable {
return r.toString(); return r.toString();
} }
} }

Loading…
Cancel
Save