1010import java .util .Collections ;
1111import java .util .HashMap ;
1212import java .util .Map ;
13- import java .util .regex .Matcher ;
14- import java .util .regex .Pattern ;
1513
1614/**
1715 * The email information for the transaction.
@@ -21,8 +19,6 @@ public final class Email extends AbstractModel {
2119 private final boolean hashAddress ;
2220 private final String domain ;
2321 private static final Map <String , String > typoDomains ;
24- private static final Pattern addressDashRegex ;
25- private static final Pattern addressPlusRegex ;
2622
2723 static {
2824 HashMap <String , String > m = new HashMap <String , String >() {{
@@ -39,9 +35,6 @@ public final class Email extends AbstractModel {
3935 }};
4036
4137 typoDomains = Collections .unmodifiableMap (m );
42-
43- addressDashRegex = Pattern .compile ("\\ A([^-]+)-.*\\ z" );
44- addressPlusRegex = Pattern .compile ("\\ A([^+]+)\\ +.*\\ z" );
4538 }
4639
4740 private Email (Email .Builder builder ) {
@@ -175,15 +168,15 @@ private String cleanAddress(String address) {
175168
176169 domain = cleanDomain (domain );
177170
178- Pattern p ;
171+ int stopChar ;
179172 if (domain .equals ("yahoo.com" )) {
180- p = addressDashRegex ;
173+ stopChar = '-' ;
181174 } else {
182- p = addressPlusRegex ;
175+ stopChar = '+' ;
183176 }
184- Matcher m = p . matcher ( localPart );
185- if (m . find () ) {
186- localPart = m . replaceFirst ( m . group ( 1 ) );
177+ int stopCharIndex = localPart . indexOf ( stopChar );
178+ if (stopCharIndex > 0 ) {
179+ localPart = localPart . substring ( 0 , stopCharIndex );
187180 }
188181
189182 return localPart + "@" + domain ;
0 commit comments