Revision: 29224
          http://sourceforge.net/p/bibdesk/svn/29224
Author:   hofman
Date:     2025-04-27 22:06:07 +0000 (Sun, 27 Apr 2025)
Log Message:
-----------
Implement CQL forrmatter in yaz

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/indexdata/yaz/objc/ZOOMQuery.h
    trunk/bibdesk_vendorsrc/indexdata/yaz/objc/ZOOMQuery.m

Modified: trunk/bibdesk_vendorsrc/indexdata/yaz/objc/ZOOMQuery.h
===================================================================
--- trunk/bibdesk_vendorsrc/indexdata/yaz/objc/ZOOMQuery.h      2025-04-27 
21:56:26 UTC (rev 29223)
+++ trunk/bibdesk_vendorsrc/indexdata/yaz/objc/ZOOMQuery.h      2025-04-27 
22:06:07 UTC (rev 29224)
@@ -93,4 +93,12 @@
 
 @end
 
+/*!
+    @class       ZOOMCQLQueryFormatter
+    @superclass  NSFormatter
+    @abstract    An NSFormatter subclass that validates the query syntax by 
attempting to convert CQL to RPN.  The formatter's control delegate should 
implement the appropriate failure message to display an error to the user.
+*/
+@interface ZOOMCQLQueryFormatter : NSFormatter
+@end
+
 NS_ASSUME_NONNULL_END

Modified: trunk/bibdesk_vendorsrc/indexdata/yaz/objc/ZOOMQuery.m
===================================================================
--- trunk/bibdesk_vendorsrc/indexdata/yaz/objc/ZOOMQuery.m      2025-04-27 
21:56:26 UTC (rev 29223)
+++ trunk/bibdesk_vendorsrc/indexdata/yaz/objc/ZOOMQuery.m      2025-04-27 
22:06:07 UTC (rev 29224)
@@ -121,33 +121,33 @@
 - (ZOOM_query)zoomQuery { return _query; }
 
 @end
-        
+
 @implementation ZOOMCCLQueryFormatter
 
 - (id)init
 {
-    return [self initWithConfigString:nil];
+return [self initWithConfigString:nil];
 }
 
 - (id)initWithConfigString:(NSString *)config;
 {
-    self = [super init];
-    if (self) {
-        const char *config_cstr = config ? [config UTF8String] : [ZOOMQuery 
defaultConfigCString];
-        size_t len = strlen(config_cstr) + 1;
-        char *copy = malloc(len * sizeof(char));
-        
-        // copy so that we can free it later
-        strncpy(copy, config_cstr, len);
-        _config = copy;
-    }
-    return self;
+self = [super init];
+if (self) {
+const char *config_cstr = config ? [config UTF8String] : [ZOOMQuery 
defaultConfigCString];
+size_t len = strlen(config_cstr) + 1;
+char *copy = malloc(len * sizeof(char));
+
+// copy so that we can free it later
+strncpy(copy, config_cstr, len);
+_config = copy;
 }
+return self;
+}
 
 - (void)dealloc
 {
-    free((void *)_config);
-    _config = NULL;
+free((void *)_config);
+_config = NULL;
 }
 
 - (NSString *)stringForObjectValue:(id)obj { return obj; }
@@ -154,27 +154,55 @@
 
 - (BOOL)getObjectValue:(id *)obj forString:(NSString *)string 
errorDescription:(NSString **)error;
 {
-    BOOL success;
-    if (string && [@"" isEqualToString:string] == NO) {
-        int status, err, errorPosition = 0;
-        
-        // A user reported a crash under +[NSString stringWithFormat:...] 
because errstring and errorPosition apparently aren't initialized under all 
circumstances, and we were using garbage.
-        const char *errstring = "Unknown error";
-        ZOOM_query query = ZOOM_query_create();
-        status = ZOOM_query_ccl2rpn(query, [string UTF8String], _config, &err, 
&errstring, &errorPosition);
-        if (status) {
-            if (error) *error = [NSString stringWithFormat:@"This is not a 
valid CCL query.  The parser reports \"%s\" (at position %d).", errstring, 
errorPosition];
-            success = NO;
-        } else {
-            success = YES;
-        }
-        ZOOM_query_destroy(query);
-    } else {
-        success = YES;
-    }
-    *obj = string;
-    return success;
+BOOL success;
+if (string && [@"" isEqualToString:string] == NO) {
+int status, err, errorPosition = 0;
+
+// A user reported a crash under +[NSString stringWithFormat:...] because 
errstring and errorPosition apparently aren't initialized under all 
circumstances, and we were using garbage.
+const char *errstring = "Unknown error";
+ZOOM_query query = ZOOM_query_create();
+status = ZOOM_query_ccl2rpn(query, [string UTF8String], _config, &err, 
&errstring, &errorPosition);
+if (status) {
+    if (error) *error = [NSString stringWithFormat:@"This is not a valid CCL 
query.  The parser reports \"%s\" (at position %d).", errstring, errorPosition];
+    success = NO;
+} else {
+    success = YES;
 }
+ZOOM_query_destroy(query);
+} else {
+success = YES;
+}
+*obj = string;
+return success;
+}
 
 @end
 
+@implementation ZOOMCQLQueryFormatter
+
+- (NSString *)stringForObjectValue:(id)obj { return obj; }
+
+- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string 
errorDescription:(NSString **)error;
+{
+BOOL success;
+if (string && [@"" isEqualToString:string] == NO) {
+int status;
+
+ZOOM_query query = ZOOM_query_create();
+status = ZOOM_query_cql2rpn(query, [string UTF8String], 0);
+if (status) {
+    if (error) *error = @"This is not a valid CQL query.";
+    success = NO;
+} else {
+    success = YES;
+}
+ZOOM_query_destroy(query);
+} else {
+success = YES;
+}
+*obj = string;
+return success;
+}
+
+@end
+

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to