Revision: 12811
          http://sourceforge.net/p/skim-app/code/12811
Author:   hofman
Date:     2022-03-18 22:40:33 +0000 (Fri, 18 Mar 2022)
Log Message:
-----------
Don't remove word break hyphen in cleaning method. Better check whether lines 
are consecutive to have a break.

Modified Paths:
--------------
    trunk/NSString_SKExtensions.m
    trunk/PDFSelection_SKExtensions.m

Modified: trunk/NSString_SKExtensions.m
===================================================================
--- trunk/NSString_SKExtensions.m       2022-03-18 15:29:03 UTC (rev 12810)
+++ trunk/NSString_SKExtensions.m       2022-03-18 22:40:33 UTC (rev 12811)
@@ -79,22 +79,16 @@
     NSCAssert1(buffer != NULL, @"failed to allocate memory for string of 
length %ld", (long)length);
     
     CFCharacterSetRef wsnlCharSet = 
CFCharacterSetGetPredefined(kCFCharacterSetWhitespaceAndNewline);
-    CFCharacterSetRef nlCharSet = 
CFCharacterSetGetPredefined(kCFCharacterSetNewline);
-    BOOL isFirst = NO, wasHyphen = NO, found = NO;
+    BOOL isFirst = NO, found = NO;
     CFIndex bufCnt = 0;
-    for(cnt = 0; cnt < length; cnt++){
+    for(cnt = 0; cnt < length; cnt++) {
         ch = CFStringGetCharacterFromInlineBuffer(&inlineBuffer, cnt);
-        if(NO == CFCharacterSetIsCharacterMember(wsnlCharSet, ch)){
-            wasHyphen = (ch == '-');
+        if(NO == CFCharacterSetIsCharacterMember(wsnlCharSet, ch)) {
             isFirst = YES;
             buffer[bufCnt++] = ch; // not whitespace, so we want to keep it
         } else {
-            if(isFirst){
-                if(wasHyphen && CFCharacterSetIsCharacterMember(nlCharSet, ch))
-                    bufCnt--; // ignore the last hyphen and current newline
-                else
-                    buffer[bufCnt++] = ' '; // if it's the first whitespace, 
we add a single space
-                wasHyphen = NO;
+            if (isFirst){
+                buffer[bufCnt++] = ' '; // if it's the first whitespace, we 
add a single space
                 isFirst = NO;
             }
             found = YES;
@@ -102,7 +96,7 @@
     }
     
     if (found){
-        if(buffer[(bufCnt-1)] == ' ') // we've collapsed any trailing 
whitespace, so disregard it
+        if (buffer[(bufCnt-1)] == ' ') // we've collapsed any trailing 
whitespace, so disregard it
             bufCnt--;
         
         retStr = CFStringCreateWithCharacters(allocator, buffer, bufCnt);

Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m   2022-03-18 15:29:03 UTC (rev 12810)
+++ trunk/PDFSelection_SKExtensions.m   2022-03-18 22:40:33 UTC (rev 12811)
@@ -76,6 +76,19 @@
     return [[self safeFirstPage] displayLabel];
 }
 
+static inline BOOL consecutiveSelections(PDFSelection *sel1, PDFSelection 
*sel2) {
+    PDFPage *page = [sel1 safeLastPage];
+    if ([[sel2 safeFirstPage] isEqual:page] == NO)
+        return NO;
+    NSUInteger i = [sel1 safeIndexOfLastCharacterOnPage:page];
+    NSUInteger j = [sel2 safeIndexOfFirstCharacterOnPage:page];
+    if (i + 1 == j)
+        return YES;
+    if (i + 2 != j)
+        return NO;
+    return [[NSCharacterSet whitespaceAndNewlineCharacterSet] 
characterIsMember:[[page string] characterAtIndex:i + 1]];
+}
+
 - (NSString *)compactedCleanedString {
     NSArray *lines = [self selectionsByLine];
     if ([lines count] < 2)
@@ -86,7 +99,7 @@
         NSString *str = [[[line string] stringByRemovingAliens] 
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
         if ([str length] == 0) continue;
         NSInteger l = [string length];
-        if (l > 1 && [string characterAtIndex:l - 1] == '-' && 
[[NSCharacterSet letterCharacterSet] characterIsMember:[string 
characterAtIndex:l - 2]] && [line safeIndexOfFirstCharacterOnPage:nil] <= 
[lastLine safeIndexOfLastCharacterOnPage:nil] + 2)
+        if (l > 1 && [string characterAtIndex:l - 1] == '-' && 
[[NSCharacterSet letterCharacterSet] characterIsMember:[string 
characterAtIndex:l - 2]] && consecutiveSelections(lastLine, line))
             [string deleteCharactersInRange:NSMakeRange(l - 1, 1)];
         else if (l > 0)
             [string appendString:@" "];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to