Mhurd has submitted this change and it was merged.

Change subject: Address nested parentheses in Share a Fact
......................................................................


Address nested parentheses in Share a Fact

Additionally, trim whitespace before semicolons.

Also, add tests for various utility instance methods.

Finally, remove the circle R from overlay per Moiz and Legal.

Bug T91846

Change-Id: I3c26877c7e4e220e84af9f192423384ea3b5c64e
---
M WikipediaUnitTests/NSString+WMFHTMLParsingTests.m
M wikipedia/Categories/NSString+WMFHTMLParsing.h
M wikipedia/Categories/NSString+WMFHTMLParsing.m
M wikipedia/View Controllers/ShareCard/ShareCard.xib
4 files changed, 177 insertions(+), 95 deletions(-)

Approvals:
  Fjalapeno: Looks good to me, but someone else must approve
  Mhurd: Looks good to me, approved
  Bgerstle: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/WikipediaUnitTests/NSString+WMFHTMLParsingTests.m 
b/WikipediaUnitTests/NSString+WMFHTMLParsingTests.m
index 698180d..82de594 100644
--- a/WikipediaUnitTests/NSString+WMFHTMLParsingTests.m
+++ b/WikipediaUnitTests/NSString+WMFHTMLParsingTests.m
@@ -33,8 +33,52 @@
 }
 
 - (void)testAdequateSnippet {
-    NSString *string = @"<p>Dog (woof) [horse] adequately long string</p>";
-    XCTAssertEqualObjects([string wmf_getStringSnippetWithoutHTML], @"Dog 
adequately long string");
+    NSString *string = @"<p>Dog (woof (w00t)) [horse] adequately long string 
historically 40 characters.</p>";
+    XCTAssertEqualObjects([string wmf_getStringSnippetWithoutHTML],
+                          @"Dog adequately long string historically 40 
characters.");
+}
+
+- (void)testConsecutiveNewlinesCollapsing {
+    NSString *string = @"\n\nHola\n\n";
+    XCTAssertEqualObjects([string wmf_stringByCollapsingConsecutiveNewlines],
+                          @"\nHola\n");
+}
+
+- (void)testNestedParenthesesRemoval {
+        NSString *string = @"He(a(b(c(d)e)f)g)llo";
+        XCTAssertEqualObjects([string 
wmf_stringByRecursivelyRemovingParenthesizedContent],
+                              @"Hello");
+}
+
+- (void)testBracketedContentRemoval {
+    NSString *string = @"J[aeio]ump";
+    XCTAssertEqualObjects([string wmf_stringByRemovingBracketedContent],
+                          @"Jump");
+}
+
+- (void)testRemovalOfSpaceBeforeCommaAndSemicolon
+{
+    NSString *string = @"fish , squids ; eagles  , crows";
+    XCTAssertEqualObjects([string 
wmf_stringByRemovingWhiteSpaceBeforeCommasAndSemicolons],
+                          @"fish, squids; eagles, crows");
+}
+
+- (void)testRemovalOfSpaceBeforePeriod {
+    NSString *string = @"Yes . No 。 Maybe . So 。";
+    XCTAssertEqualObjects([string wmf_stringByRemovingWhiteSpaceBeforePeriod],
+                          @"Yes. No。 Maybe. So。");
+}
+
+- (void)testConsecutiveSpacesCollapsing {
+    NSString *string = @"          Metal          ";
+    XCTAssertEqualObjects([string wmf_stringByCollapsingConsecutiveSpaces],
+                          @" Metal ");
+}
+
+- (void)testRemovalOfLeadingOrTrailingSpacesNewlinesOrColons {
+    NSString *string = @"\n          Syncopation:\n:";
+    XCTAssertEqualObjects([string 
wmf_stringByRemovingLeadingOrTrailingSpacesNewlinesOrColons],
+                          @"Syncopation");
 }
 
 @end
diff --git a/wikipedia/Categories/NSString+WMFHTMLParsing.h 
b/wikipedia/Categories/NSString+WMFHTMLParsing.h
index 4eeb7e4..742406c 100644
--- a/wikipedia/Categories/NSString+WMFHTMLParsing.h
+++ b/wikipedia/Categories/NSString+WMFHTMLParsing.h
@@ -27,4 +27,12 @@
  */
 - (NSString*)wmf_getStringSnippetWithoutHTML;
 
+- (NSString*)wmf_stringByCollapsingConsecutiveNewlines;
+- (NSString*)wmf_stringByRecursivelyRemovingParenthesizedContent;
+- (NSString*)wmf_stringByRemovingBracketedContent;
+- (NSString*)wmf_stringByRemovingWhiteSpaceBeforeCommasAndSemicolons;
+- (NSString*)wmf_stringByRemovingWhiteSpaceBeforePeriod;
+- (NSString*)wmf_stringByCollapsingConsecutiveSpaces;
+- (NSString*)wmf_stringByRemovingLeadingOrTrailingSpacesNewlinesOrColons;
+
 @end
diff --git a/wikipedia/Categories/NSString+WMFHTMLParsing.m 
b/wikipedia/Categories/NSString+WMFHTMLParsing.m
index 9c06619..75c0579 100644
--- a/wikipedia/Categories/NSString+WMFHTMLParsing.m
+++ b/wikipedia/Categories/NSString+WMFHTMLParsing.m
@@ -41,82 +41,124 @@
            result : nil;
 }
 
+
+#pragma mark - String simplification and cleanup
 + (NSString*)wmf_stringSnippetSimplifiedInString:(NSString*)string {
-    NSString* result                   = [string 
stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];
-    NSError* err                       = nil;
-    NSRegularExpression* newlinesRegex = [NSRegularExpression
-                                          
regularExpressionWithPattern:@"\n{2,}"
-                                                               options:0
-                                                                 error:&err];
-    NSRange range = NSMakeRange(0, result.length);
-    result = [newlinesRegex stringByReplacingMatchesInString:result
-                                                     options:0
-                                                       range:range
-                                                withTemplate:@"\n"];
+    NSString* result = [string stringByReplacingOccurrencesOfString:@"&amp;" 
withString:@"&"];
+    result = [string stringByReplacingOccurrencesOfString:@"&gt;" 
withString:@">"];
+    result = [string stringByReplacingOccurrencesOfString:@"&lt;" 
withString:@"<"];
+    result = [result wmf_stringByCollapsingConsecutiveNewlines];
+    result = [result wmf_stringByRecursivelyRemovingParenthesizedContent];
+    result = [result wmf_stringByRemovingBracketedContent];
+    result = [result wmf_stringByRemovingWhiteSpaceBeforeCommasAndSemicolons];
+    result = [result wmf_stringByRemovingWhiteSpaceBeforePeriod];
+    result = [result wmf_stringByCollapsingConsecutiveSpaces];
+    return [result 
wmf_stringByRemovingLeadingOrTrailingSpacesNewlinesOrColons];
+}
 
-
-    // We probably don't want to try to handle ideographic parens
-    err = nil;
-    NSRegularExpression* parensRegex = [NSRegularExpression
-                                        
regularExpressionWithPattern:@"[(][^)]+[)]"
-                                                             options:0
-                                                               error:&err];
-    range  = NSMakeRange(0, result.length);
-    result = [parensRegex stringByReplacingMatchesInString:result
+- (NSString*)wmf_stringByCollapsingConsecutiveNewlines {
+    static NSRegularExpression* newlinesRegex;
+    if (!newlinesRegex) {
+        newlinesRegex = [NSRegularExpression
+                         regularExpressionWithPattern:@"\n{2,}"
+                                              options:0
+                                                error:nil];
+    }
+    return [newlinesRegex stringByReplacingMatchesInString:self
                                                    options:0
-                                                     range:range
-                                              withTemplate:@""];
+                                                     range:NSMakeRange(0, 
self.length)
+                                              withTemplate:@"\n"];
+}
 
-    // Nor do we want to try to handle ideographic brackets
-    err = nil;
-    NSRegularExpression* bracketsRegex = [NSRegularExpression
-                                          
regularExpressionWithPattern:@"\\[[^]]+]"
-                                                               options:0
-                                                                 error:&err];
-    range  = NSMakeRange(0, result.length);
-    result = [bracketsRegex stringByReplacingMatchesInString:result
-                                                     options:0
-                                                       range:range
-                                                withTemplate:@""];
+- (NSString*)wmf_stringByRecursivelyRemovingParenthesizedContent {
+    // We probably don't want to handle ideographic parens
+    static NSRegularExpression* parensRegex;
+    if (!parensRegex) {
+        parensRegex = [NSRegularExpression
+                       regularExpressionWithPattern:@"[(][^()]+[)]"
+                                            options:0
+                                              error:nil];
+    }
 
+    NSString* string = [self copy];
+    NSString* oldResult;
+    NSRange range;
+    do {
+        oldResult = [string copy];
+        range     = NSMakeRange(0, string.length);
+        string    = [parensRegex stringByReplacingMatchesInString:string
+                                                          options:0
+                                                            range:range
+                                                     withTemplate:@""];
+    } while (![oldResult isEqualToString:string]);
+    return string;
+}
+
+- (NSString*)wmf_stringByRemovingBracketedContent {
+    // We don't care about ideographic brackets
+    // Nested bracketing unseen thus far
+    static NSRegularExpression* bracketedRegex;
+    if (!bracketedRegex) {
+        bracketedRegex = [NSRegularExpression
+                          regularExpressionWithPattern:@"\\[[^]]+]"
+                                               options:0
+                                                 error:nil];
+    }
+    return [bracketedRegex stringByReplacingMatchesInString:self
+                                                    options:0
+                                                      range:NSMakeRange(0, 
self.length)
+                                               withTemplate:@""];
+}
+
+- (NSString*)wmf_stringByRemovingWhiteSpaceBeforeCommasAndSemicolons {
     // Unlike parens and brackets and unlike doubled up space in general,
-    // we do not want whitespace preceding the comma or ideographic comma
-    err = nil;
-    NSRegularExpression* whitespaceCommaRegex = [NSRegularExpression
-                                                 
regularExpressionWithPattern:@"\\s+([,、])"
-                                                                      options:0
-                                                                        
error:&err];
-    range  = NSMakeRange(0, result.length);
-    result = [whitespaceCommaRegex stringByReplacingMatchesInString:result
-                                                            options:0
-                                                              range:range
-                                                       withTemplate:@"$1"];
+    // we do not want whitespace preceding the comma, ideographic comma,
+    // or semicolon
+    static NSRegularExpression* spaceCommaColonRegex;
+    if (!spaceCommaColonRegex) {
+        spaceCommaColonRegex = [NSRegularExpression
+                                regularExpressionWithPattern:@"\\s+([,、;])"
+                                                     options:0
+                                                       error:nil];
+    }
+    return [spaceCommaColonRegex stringByReplacingMatchesInString:self
+                                                          options:0
+                                                            
range:NSMakeRange(0, self.length)
+                                                     withTemplate:@"$1"];
+}
 
+- (NSString*)wmf_stringByRemovingWhiteSpaceBeforePeriod {
     // Ideographic stops from TextExtracts, which were from OpenSearch
-    err = nil;
-    NSRegularExpression* whitespacePeriodRegex = [NSRegularExpression
-                                                  
regularExpressionWithPattern:@"\\s+([\\.|。|.|。])"
-                                                                       
options:0
-                                                                         
error:&err];
-    range  = NSMakeRange(0, result.length);
-    result = [whitespacePeriodRegex stringByReplacingMatchesInString:result
-                                                             options:0
-                                                               range:range
-                                                        withTemplate:@"$1"];
+    static NSRegularExpression* spacePeriodRegex;
+    if (!spacePeriodRegex) {
+        spacePeriodRegex = [NSRegularExpression
+                                
regularExpressionWithPattern:@"\\s+([\\.|。|.|。])"
+                                                     options:0
+                                                       error:nil];
+    }
+    return [spacePeriodRegex stringByReplacingMatchesInString:self
+                                                          options:0
+                                                            
range:NSMakeRange(0, self.length)
+                                                     withTemplate:@"$1"];
+}
 
+- (NSString*)wmf_stringByCollapsingConsecutiveSpaces {
     // In practice, we rarely care about doubled up whitespace in the
     // string except for the actual space character
-    err = nil;
-    NSRegularExpression* spacesRegex = [NSRegularExpression
-                                        regularExpressionWithPattern:@" {2,}"
-                                                             options:0
-                                                               error:&err];
-    range  = NSMakeRange(0, result.length);
-    result = [spacesRegex stringByReplacingMatchesInString:result
-                                                   options:0
-                                                     range:range
-                                              withTemplate:@" "];
+    static NSRegularExpression* spacesRegex;
+    if (!spacesRegex) {
+        spacesRegex = [NSRegularExpression
+                       regularExpressionWithPattern:@" {2,}"
+                                            options:0
+                                              error:nil];
+    }
+    return [spacesRegex stringByReplacingMatchesInString:self
+                                                 options:0
+                                                   range:NSMakeRange(0, 
self.length)
+                                            withTemplate:@" "];
+}
 
+- (NSString*)wmf_stringByRemovingLeadingOrTrailingSpacesNewlinesOrColons {
     // Note about trailing colon characters: they usually look strange if kept,
     // and removing them (plus spaces and newlines) doesn't often create merged
     // words that look bad - these are usually at tag boundaries. For Latinized
@@ -124,18 +166,18 @@
     // But as a matter of markup structure, something like a <p> tag
     // shouldn't be </p> closed until something like <ul>...</ul> is closed.
     // In fact, some sections have this layout, and some do not.
-    err = nil;
-    NSRegularExpression* leadingTrailingWhitespaceNewlineRegex = 
[NSRegularExpression
-                                                                  
regularExpressionWithPattern:@"^[\\s\n]+|[\\s\n:]+$"
-                                                                               
        options:0
-                                                                               
          error:&err];
-    range  = NSMakeRange(0, result.length);
-    result = [leadingTrailingWhitespaceNewlineRegex 
stringByReplacingMatchesInString:result
-                                                                             
options:0
-                                                                               
range:range
-                                                                        
withTemplate:@""];
-
-    return result;
+    static NSRegularExpression* leadTrailColonRegex;
+    if (!leadTrailColonRegex) {
+        leadTrailColonRegex = [NSRegularExpression
+                               
regularExpressionWithPattern:@"^[\\s\n]+|[\\s\n:]+$"
+                                                    options:0
+                                                      error:nil];
+    }
+    return [leadTrailColonRegex stringByReplacingMatchesInString:self
+                                                         options:0
+                                                           
range:NSMakeRange(0, self.length)
+                                                    withTemplate:@""];
 }
 
+
 @end
diff --git a/wikipedia/View Controllers/ShareCard/ShareCard.xib 
b/wikipedia/View Controllers/ShareCard/ShareCard.xib
index b84bc4b..3bf301c 100644
--- a/wikipedia/View Controllers/ShareCard/ShareCard.xib
+++ b/wikipedia/View Controllers/ShareCard/ShareCard.xib
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" 
toolsVersion="6254" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" 
propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" 
toolsVersion="6751" systemVersion="13F1066" targetRuntime="iOS.CocoaTouch" 
propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" 
version="6247"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" 
version="6736"/>
     </dependencies>
     <objects>
         <placeholder placeholderIdentifier="IBFilesOwner" id="-1" 
userLabel="File's Owner" customClass="WMFShareCardViewController">
@@ -45,7 +45,7 @@
                     </constraints>
                 </imageView>
                 <imageView userInteractionEnabled="NO" 
contentMode="scaleAspectFit" horizontalHuggingPriority="251" 
verticalHuggingPriority="251" image="Wikipedia_wordmark_gray.png" 
translatesAutoresizingMaskIntoConstraints="NO" id="6HC-uN-YYr" 
userLabel="Wikipedia Text Logo">
-                    <rect key="frame" x="437" y="300" width="165" height="42"/>
+                    <rect key="frame" x="446" y="300" width="165" height="42"/>
                     <constraints>
                         <constraint firstAttribute="width" constant="165" 
id="0M9-6P-ngj"/>
                         <constraint firstAttribute="height" constant="42" 
id="lae-oj-fPO"/>
@@ -90,16 +90,6 @@
                     <color key="shadowColor" white="0.33333333333333331" 
alpha="1" colorSpace="calibratedWhite"/>
                     <size key="shadowOffset" width="0.0" height="0.0"/>
                 </label>
-                <label opaque="NO" userInteractionEnabled="NO" 
contentMode="left" horizontalHuggingPriority="251" 
verticalHuggingPriority="251" text="®" textAlignment="center" 
lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" 
adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="14" 
translatesAutoresizingMaskIntoConstraints="NO" id="5Yo-yI-rwI" 
userLabel="Registered Character">
-                    <rect key="frame" x="595" y="306" width="14" height="14"/>
-                    <constraints>
-                        <constraint firstAttribute="height" constant="14" 
id="pCZ-Xx-JCh"/>
-                        <constraint firstAttribute="width" constant="14" 
id="zd9-Sv-7Sd"/>
-                    </constraints>
-                    <fontDescription key="fontDescription" 
name="TimesNewRomanPSMT" family="Times New Roman" pointSize="12"/>
-                    <color key="textColor" red="0.87058823529411766" 
green="0.87058823529411766" blue="0.87058823529411766" alpha="1" 
colorSpace="calibratedRGB"/>
-                    <nil key="highlightedColor"/>
-                </label>
             </subviews>
             <color key="backgroundColor" red="0.0" green="0.0" blue="0.0" 
alpha="1" colorSpace="calibratedRGB"/>
             <constraints>
@@ -110,17 +100,15 @@
                 <constraint firstAttribute="trailing" secondItem="ihv-br-w7Q" 
secondAttribute="trailing" constant="594" id="Fa7-xI-sO6"/>
                 <constraint firstItem="QlQ-cG-u6Y" firstAttribute="top" 
secondItem="iN0-l3-epB" secondAttribute="top" constant="1" id="I1H-MI-rGN"/>
                 <constraint firstItem="6HC-uN-YYr" firstAttribute="top" 
secondItem="iN0-l3-epB" secondAttribute="top" constant="300" id="IRD-c1-xQ1"/>
-                <constraint firstItem="6HC-uN-YYr" firstAttribute="leading" 
secondItem="iN0-l3-epB" secondAttribute="leading" constant="437" 
id="Jth-di-SuC"/>
                 <constraint firstAttribute="trailing" secondItem="dbe-nb-kfi" 
secondAttribute="trailing" constant="250" id="PFY-gP-kCk"/>
                 <constraint firstAttribute="trailing" secondItem="rjC-wW-yPe" 
secondAttribute="trailing" constant="250" id="SfX-Oa-xFJ"/>
-                <constraint firstItem="5Yo-yI-rwI" firstAttribute="top" 
secondItem="iN0-l3-epB" secondAttribute="top" constant="306" id="UqO-oR-9Ri"/>
                 <constraint firstItem="jvd-fN-IRx" firstAttribute="leading" 
secondItem="iN0-l3-epB" secondAttribute="leading" constant="66" 
id="WCt-t0-W80"/>
                 <constraint firstAttribute="trailing" secondItem="QlQ-cG-u6Y" 
secondAttribute="trailing" constant="30" id="Y9l-1g-Oo7"/>
-                <constraint firstItem="5Yo-yI-rwI" firstAttribute="left" 
secondItem="6HC-uN-YYr" secondAttribute="right" constant="-7" id="fhg-D4-4AE"/>
-                <constraint firstAttribute="trailing" secondItem="6HC-uN-YYr" 
secondAttribute="trailing" constant="38" id="jVI-Mw-VWG"/>
+                <constraint firstAttribute="trailing" secondItem="6HC-uN-YYr" 
secondAttribute="trailing" constant="29" id="dXe-Br-38A"/>
                 <constraint firstItem="ihv-br-w7Q" firstAttribute="top" 
secondItem="dbe-nb-kfi" secondAttribute="bottom" constant="5" id="n83-t1-RUk"/>
                 <constraint firstItem="rjC-wW-yPe" firstAttribute="leading" 
secondItem="iN0-l3-epB" secondAttribute="leading" constant="30" 
id="nv3-ra-Qgn"/>
                 <constraint firstAttribute="trailing" secondItem="Sjf-Tp-DH9" 
secondAttribute="trailing" constant="576" id="ooM-aW-c1A"/>
+                <constraint firstItem="6HC-uN-YYr" firstAttribute="leading" 
secondItem="iN0-l3-epB" secondAttribute="leading" constant="446" 
id="r6f-yl-9co"/>
                 <constraint firstItem="Sjf-Tp-DH9" firstAttribute="top" 
secondItem="iN0-l3-epB" secondAttribute="top" constant="319" id="sf5-h3-ktL"/>
                 <constraint firstItem="dbe-nb-kfi" firstAttribute="leading" 
secondItem="iN0-l3-epB" secondAttribute="leading" constant="30" 
id="si1-eO-mqn"/>
                 <constraint firstItem="ihv-br-w7Q" firstAttribute="top" 
secondItem="iN0-l3-epB" secondAttribute="top" constant="319" id="uzH-it-j9k"/>

-- 
To view, visit https://gerrit.wikimedia.org/r/196298
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3c26877c7e4e220e84af9f192423384ea3b5c64e
Gerrit-PatchSet: 7
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: Bgerstle <[email protected]>
Gerrit-Reviewer: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: Fjalapeno <[email protected]>
Gerrit-Reviewer: Mhurd <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to