Revision: 13830
          http://sourceforge.net/p/skim-app/code/13830
Author:   hofman
Date:     2023-12-04 17:54:44 +0000 (Mon, 04 Dec 2023)
Log Message:
-----------
use some macros for constant strings

Modified Paths:
--------------
    trunk/SkimNotes/PDFDocument_SKNExtensions.m
    trunk/SkimNotes/SKNExtendedAttributeManager.m

Modified: trunk/SkimNotes/PDFDocument_SKNExtensions.m
===================================================================
--- trunk/SkimNotes/PDFDocument_SKNExtensions.m 2023-12-04 17:32:44 UTC (rev 
13829)
+++ trunk/SkimNotes/PDFDocument_SKNExtensions.m 2023-12-04 17:54:44 UTC (rev 
13830)
@@ -57,6 +57,9 @@
 #define SKNRectFromString(string)   NSRectFromString(string)
 #define SKNEqualRects(rect1, rect2) NSEqualRects(NSIntegralRect(rect1), 
NSIntegralRect(rect2))
 
+#define PDF_EXTENSION  @"pdf"
+#define PDFD_EXTENSION @"pdfd"
+
 #if !defined(MAC_OS_X_VERSION_10_12) || MAC_OS_X_VERSION_MAX_ALLOWED < 
MAC_OS_X_VERSION_10_12
 @interface PDFAnnotation (SKNSierraDeclarations)
 - (id)valueForAnnotationKey:(NSString *)key;
@@ -77,9 +80,9 @@
 - (id)initWithURL:(NSURL *)url readSkimNotes:(NSArray<PDFAnnotation *> 
**)notes {
     NSFileManager *fm = [NSFileManager defaultManager];
     NSURL *pdfURL = url;
-    BOOL isPDFBundle = [[[url path] pathExtension] 
caseInsensitiveCompare:@"pdfd"] == NSOrderedSame;
+    BOOL isPDFBundle = [[[url path] pathExtension] 
caseInsensitiveCompare:PDFD_EXTENSION] == NSOrderedSame;
     if (isPDFBundle)
-        pdfURL = [fm bundledFileURLWithExtension:@"pdf" inPDFBundleAtURL:url 
error:NULL];
+        pdfURL = [fm bundledFileURLWithExtension:PDF_EXTENSION 
inPDFBundleAtURL:url error:NULL];
     self = [self initWithURL:pdfURL];
     if (self) {
         NSArray *noteDicts = nil;

Modified: trunk/SkimNotes/SKNExtendedAttributeManager.m
===================================================================
--- trunk/SkimNotes/SKNExtendedAttributeManager.m       2023-12-04 17:32:44 UTC 
(rev 13829)
+++ trunk/SkimNotes/SKNExtendedAttributeManager.m       2023-12-04 17:54:44 UTC 
(rev 13830)
@@ -50,7 +50,8 @@
 #define WRAPPER_KEY_SUFFIX      @"_has_wrapper"
 #define FRAGMENTS_KEY_SUFFIX    @"_number_of_fragments"
 
-#define SYNCABLE_FLAG @"#S"
+#define SYNCABLE_FLAG      @"#S"
+#define SYNCABLE_SEPARATOR @"#"
 
 #ifndef NSFoundationVersionNumber10_10
 #define NSFoundationVersionNumber10_10 1151.16
@@ -245,7 +246,7 @@
     NSError *err = nil;
     NSData *attribute = [self copyRawExtendedAttributeNamed:attr atPath:path 
traverseLink:follow error:&err];
     
-    if (attribute == nil && [err code] == ENOATTR && [attr 
rangeOfString:@"#"].location == NSNotFound) {
+    if (attribute == nil && [err code] == ENOATTR && [attr 
rangeOfString:SYNCABLE_SEPARATOR].location == NSNotFound) {
         NSString *sattr = [attr stringByAppendingString:SYNCABLE_FLAG];
         attribute = [self copyRawExtendedAttributeNamed:sattr atPath:path 
traverseLink:follow error:&err];
         if (attribute)
@@ -269,7 +270,7 @@
             if (success == NO)
                 NSLog(@"failed to read unique key %@ for %lu fragments from 
property list.", _uniqueKey, (long)numberOfFragments);
             
-            NSUInteger j = [attr rangeOfString:@"#"].location;
+            NSUInteger j = [attr rangeOfString:SYNCABLE_SEPARATOR].location;
             NSString *suffix = j == NSNotFound || j == [attr length] - 1 ? @"" 
: [attr substringFromIndex:j];
             
             // reassemble the original data object
@@ -334,7 +335,7 @@
 - (BOOL)setExtendedAttributeNamed:(NSString *)attr toValue:(NSData *)value 
atPath:(NSString *)path options:(SKNXattrFlags)options error:(NSError **)error;
 {
     
-    if((options & kSKNXattrSyncable) && NSFoundationVersionNumber >= 
NSFoundationVersionNumber10_10 && [attr rangeOfString:@"#"].location == 
NSNotFound){
+    if((options & kSKNXattrSyncable) && NSFoundationVersionNumber >= 
NSFoundationVersionNumber10_10 && [attr 
rangeOfString:SYNCABLE_SEPARATOR].location == NSNotFound){
         attr = [attr stringByAppendingString:SYNCABLE_FLAG];
     }
 
@@ -375,7 +376,7 @@
         NSUInteger i;
         const char *valuePtr = [value bytes];
         
-        NSUInteger j = [attr rangeOfString:@"#"].location;
+        NSUInteger j = [attr rangeOfString:SYNCABLE_SEPARATOR].location;
         NSString *suffix = j == NSNotFound || j == [attr length] - 1 ? @"" : 
[attr substringFromIndex:j];
         
         for (i = 0; success && i < numberOfFragments; i++) {
@@ -440,7 +441,7 @@
     ssize_t status;
     status = getxattr(fsPath, attrName, NULL, 0, 0, xopts);
     
-    if (status == -1 && errno == ENOATTR && [attr rangeOfString:@"#"].location 
== NSNotFound){
+    if (status == -1 && errno == ENOATTR && [attr 
rangeOfString:SYNCABLE_SEPARATOR].location == NSNotFound){
         NSString *sattr = [attr stringByAppendingString:SYNCABLE_FLAG];
         const char *sattrName = [sattr UTF8String];
         status = getxattr(fsPath, sattrName, NULL, 0, 0, xopts);
@@ -477,7 +478,7 @@
                 NSUInteger i, numberOfFragments = [[plist 
objectForKey:_fragmentsKey] unsignedIntegerValue];
                 NSString *name;
                 
-                NSUInteger j = [attr rangeOfString:@"#"].location;
+                NSUInteger j = [attr 
rangeOfString:SYNCABLE_SEPARATOR].location;
                 NSString *suffix = j == NSNotFound || j == [attr length] - 1 ? 
@"" : [attr substringFromIndex:j];
                 
                 // remove the sub attributes
@@ -506,7 +507,7 @@
         if(error) *error = [self xattrError:errno forPath:path];
         return NO;
     } else {
-        if ([attr rangeOfString:@"#"].location == NSNotFound){
+        if ([attr rangeOfString:SYNCABLE_SEPARATOR].location == NSNotFound){
             attr = [attr stringByAppendingString:SYNCABLE_FLAG];
             [self removeExtendedAttributeNamed:attr atPath:path 
traverseLink:follow error:NULL];
         }

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to