emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 96e5d8c 1/2: Extend NSString further and use the new methods


From: Alan Third
Subject: master 96e5d8c 1/2: Extend NSString further and use the new methods
Date: Sat, 22 Aug 2020 11:32:18 -0400 (EDT)

branch: master
commit 96e5d8ce0d92eacbd7e237e50f0b572bb56e6d66
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>

    Extend NSString further and use the new methods
    
    * src/nsfns.m (ns_set_icon_name):
    (ns_set_name):
    (ns_set_represented_filename):
    (ns_implicitly_set_icon_type):
    (ns_set_icon_type):
    (ns_appkit_version_str):
    (Fx_create_frame):
    (Fns_read_file_name):
    (Fns_get_resource):
    (Fns_set_resource):
    (Fns_list_colors):
    (Fns_perform_service):
    (ns_do_applescript): Use the new NSString methods.
    ([NSString stringWithLispString:]): Fix the surrogate algorithm.
    ([NSString lispString]): New method.
    * src/nsterm.h (NSString): Add new method.
    * src/nsterm.m ([EmacsApp openFile:]):
    ([EmacsApp requestService:userData:error:]):
    ([EmacsApp fulfillService:withArg:]):
    ([EmacsView changeFont:]):
    ([EmacsView setMarkedText:selectedRange:]):
    ([EmacsView initFrameFromEmacs:]):
    ([EmacsView performDragOperation:]):
    ([EmacsView performDragOperation:]):
    ([EmacsView performDragOperation:]):
    ([EmacsWindow accessibilityAttributeValue:]): Use the new NSString
    methods.
---
 src/nsfns.m  | 78 +++++++++++++++++++++++++++++-------------------------------
 src/nsterm.h |  1 +
 src/nsterm.m | 25 +++++++++----------
 3 files changed, 50 insertions(+), 54 deletions(-)

diff --git a/src/nsfns.m b/src/nsfns.m
index 5fca155..c795649 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -390,12 +390,11 @@ ns_set_icon_name (struct frame *f, Lisp_Object arg, 
Lisp_Object oldval)
   /* Don't change the name if it's already NAME.  */
   if ([[view window] miniwindowTitle]
       && ([[[view window] miniwindowTitle]
-             isEqualToString: [NSString stringWithUTF8String:
-                                         SSDATA (arg)]]))
+             isEqualToString: [NSString stringWithLispString:arg]]))
     return;
 
   [[view window] setMiniwindowTitle:
-        [NSString stringWithUTF8String: SSDATA (arg)]];
+        [NSString stringWithLispString:arg]];
 }
 
 static void
@@ -437,7 +436,7 @@ ns_set_name (struct frame *f, Lisp_Object name, int 
explicit)
     return;
 
   if (NILP (name))
-    name = build_string ([ns_app_name UTF8String]);
+    name = [ns_app_name lispString];
   else
     CHECK_STRING (name);
 
@@ -476,7 +475,7 @@ ns_set_represented_filename (struct frame *f)
     {
       encoded_filename = ENCODE_UTF_8 (filename);
 
-      fstr = [NSString stringWithUTF8String: SSDATA (encoded_filename)];
+      fstr = [NSString stringWithLispString:encoded_filename];
       if (fstr == nil) fstr = @"";
     }
   else
@@ -723,7 +722,7 @@ ns_implicitly_set_icon_type (struct frame *f)
   block_input ();
   pool = [[NSAutoreleasePool alloc] init];
   if (f->output_data.ns->miniimage
-      && [[NSString stringWithUTF8String: SSDATA (f->name)]
+      && [[NSString stringWithLispString:f->name]
                isEqualToString: [(NSImage *)f->output_data.ns->miniimage 
name]])
     {
       [pool release];
@@ -748,7 +747,7 @@ ns_implicitly_set_icon_type (struct frame *f)
       if (SYMBOLP (elt) && EQ (elt, Qt) && SSDATA (f->name)[0] == '/')
         {
           NSString *str
-            = [NSString stringWithUTF8String: SSDATA (f->name)];
+            = [NSString stringWithLispString:f->name];
           if ([[NSFileManager defaultManager] fileExistsAtPath: str])
             image = [[[NSWorkspace sharedWorkspace] iconForFile: str] retain];
         }
@@ -760,8 +759,7 @@ ns_implicitly_set_icon_type (struct frame *f)
           image = [EmacsImage allocInitFromFile: XCDR (elt)];
           if (image == nil)
             image = [[NSImage imageNamed:
-                               [NSString stringWithUTF8String:
-                                           SSDATA (XCDR (elt))]] retain];
+                               [NSString stringWithLispString:XCDR (elt)]] 
retain];
         }
     }
 
@@ -805,8 +803,7 @@ ns_set_icon_type (struct frame *f, Lisp_Object arg, 
Lisp_Object oldval)
 
   image = [EmacsImage allocInitFromFile: arg];
   if (image == nil)
-    image =[NSImage imageNamed: [NSString stringWithUTF8String:
-                                            SSDATA (arg)]];
+    image =[NSImage imageNamed: [NSString stringWithLispString:arg]];
 
   if (image == nil)
     {
@@ -840,20 +837,18 @@ ns_set_mouse_color (struct frame *f, Lisp_Object arg, 
Lisp_Object oldval)
 static Lisp_Object
 ns_appkit_version_str (void)
 {
-  char tmp[256];
+  NSString *tmp;
 
 #ifdef NS_IMPL_GNUSTEP
-  sprintf(tmp, "gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION));
+  tmp = [NSString stringWithFormat:@"gnustep-gui-%s", 
Xstr(GNUSTEP_GUI_VERSION)];
 #elif defined (NS_IMPL_COCOA)
-  NSString *osversion
-    = [[NSProcessInfo processInfo] operatingSystemVersionString];
-  sprintf(tmp, "appkit-%.2f %s",
-          NSAppKitVersionNumber,
-          [osversion UTF8String]);
+  tmp = [NSString stringWithFormat:@"appkit-%.2f %@",
+                  NSAppKitVersionNumber,
+                  [[NSProcessInfo processInfo] operatingSystemVersionString]];
 #else
-  tmp = "ns-unknown";
+  tmp = [NSString initWithUTF8String:@"ns-unknown"];
 #endif
-  return build_string (tmp);
+  return [tmp lispString];
 }
 
 
@@ -1157,7 +1152,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
      be set.  */
   if (EQ (name, Qunbound) || NILP (name) || ! STRINGP (name))
     {
-      fset_name (f, build_string ([ns_app_name UTF8String]));
+      fset_name (f, [ns_app_name lispString]);
       f->explicit_name = 0;
     }
   else
@@ -1598,12 +1593,12 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only 
directories.  */)
   Lisp_Object fname = Qnil;
 
   NSString *promptS = NILP (prompt) || !STRINGP (prompt) ? nil :
-    [NSString stringWithUTF8String: SSDATA (prompt)];
+    [NSString stringWithLispString:prompt];
   NSString *dirS = NILP (dir) || !STRINGP (dir) ?
-    [NSString stringWithUTF8String: SSDATA (BVAR (current_buffer, directory))] 
:
-    [NSString stringWithUTF8String: SSDATA (dir)];
+    [NSString stringWithLispString:BVAR (current_buffer, directory)] :
+    [NSString stringWithLispString:dir];
   NSString *initS = NILP (init) || !STRINGP (init) ? nil :
-    [NSString stringWithUTF8String: SSDATA (init)];
+    [NSString stringWithLispString:init];
   NSEvent *nxev;
 
   check_window_system (NULL);
@@ -1679,7 +1674,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only 
directories.  */)
     {
       NSString *str = ns_filename_from_panel (panel);
       if (! str) str = ns_directory_from_panel (panel);
-      if (str) fname = build_string ([str UTF8String]);
+      if (str) fname = [str lispString];
     }
 
   [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
@@ -1709,7 +1704,7 @@ If OWNER is nil, Emacs is assumed.  */)
 
   check_window_system (NULL);
   if (NILP (owner))
-    owner = build_string([ns_app_name UTF8String]);
+    owner = [ns_app_name lispString];
   CHECK_STRING (name);
 
   value = ns_get_defaults_value (SSDATA (name));
@@ -1728,20 +1723,19 @@ If VALUE is nil, the default is removed.  */)
 {
   check_window_system (NULL);
   if (NILP (owner))
-    owner = build_string ([ns_app_name UTF8String]);
+    owner = [ns_app_name lispString];
   CHECK_STRING (name);
   if (NILP (value))
     {
       [[NSUserDefaults standardUserDefaults] removeObjectForKey:
-                         [NSString stringWithUTF8String: SSDATA (name)]];
+                         [NSString stringWithLispString:name]];
     }
   else
     {
       CHECK_STRING (value);
       [[NSUserDefaults standardUserDefaults] setObject:
-                [NSString stringWithUTF8String: SSDATA (value)]
-                                        forKey: [NSString stringWithUTF8String:
-                                                         SSDATA (name)]];
+                [NSString stringWithLispString:value]
+                                        forKey: [NSString 
stringWithLispString:name]];
     }
 
   return Qnil;
@@ -2033,7 +2027,7 @@ The optional argument FRAME is currently ignored.  */)
           NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator];
           NSString *cname;
           while ((cname = [cnames nextObject]))
-            list = Fcons (build_string ([cname UTF8String]), list);
+            list = Fcons ([cname lispString], list);
 /*           for (i = [[clist allKeys] count] - 1; i >= 0; i--)
                list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i]
                                              UTF8String]), list); */
@@ -2081,13 +2075,11 @@ there was no result.  */)
 {
   id pb;
   NSString *svcName;
-  char *utfStr;
 
   CHECK_STRING (service);
   check_window_system (NULL);
 
-  utfStr = SSDATA (service);
-  svcName = [NSString stringWithUTF8String: utfStr];
+  svcName = [NSString stringWithLispString:service];
 
   pb =[NSPasteboard pasteboardWithUniqueName];
   ns_string_to_pasteboard (pb, send);
@@ -2117,7 +2109,7 @@ ns_do_applescript (Lisp_Object script, Lisp_Object 
*result)
 
   NSAppleScript *scriptObject =
     [[NSAppleScript alloc] initWithSource:
-                            [NSString stringWithUTF8String: SSDATA (script)]];
+                            [NSString stringWithLispString:script]];
 
   returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
   [scriptObject release];
@@ -2140,7 +2132,7 @@ ns_do_applescript (Lisp_Object script, Lisp_Object 
*result)
            {
              desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
              if (desc)
-               *result = build_string([[desc stringValue] UTF8String]);
+               *result = [[desc stringValue] lispString];
            }
          else
             {
@@ -3055,8 +3047,8 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n)
         *d++ = c;
       else if (c <= 0x10ffff)
         {
-          *d++ = 0xd800 + (c & 0x3ff);
-          *d++ = 0xdc00 + ((c - 0x10000) >> 10);
+          *d++ = 0xd800 + ((c - 0x10000) >> 10);
+          *d++ = 0xdc00 + (c & 0x3ff);
         }
       else
         *d++ = 0xfffd;          /* Not valid for UTF-16.  */
@@ -3066,6 +3058,12 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n)
   xfree (chars);
   return str;
 }
+
+/* Make a Lisp string from an NSString.  */
+- (Lisp_Object)lispString
+{
+  return build_string ([self UTF8String]);
+}
 @end
 
 /* ==========================================================================
diff --git a/src/nsterm.h b/src/nsterm.h
index ab868ed..b56bcad 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -364,6 +364,7 @@ typedef id instancetype;
 
 @interface NSString (EmacsString)
 + (NSString *)stringWithLispString:(Lisp_Object)string;
+- (Lisp_Object)lispString;
 @end
 
 /* ==========================================================================
diff --git a/src/nsterm.m b/src/nsterm.m
index 98c5b69..26059ab 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -5909,7 +5909,7 @@ ns_term_shutdown (int sig)
 
   emacs_event->kind = NS_NONKEY_EVENT;
   emacs_event->code = KEY_NS_OPEN_FILE_LINE;
-  ns_input_file = append2 (ns_input_file, build_string ([fileName 
UTF8String]));
+  ns_input_file = append2 (ns_input_file, [fileName lispString]);
   ns_input_line = Qnil; /* can be start or cons start,end */
   emacs_event->modifiers =0;
   EV_TRAILER (theEvent);
@@ -6273,8 +6273,7 @@ not_in_argv (NSString *arg)
                  error: (NSString **)error
 {
   [ns_pending_service_names addObject: userData];
-  [ns_pending_service_args addObject: [NSString stringWithUTF8String:
-      SSDATA (ns_string_from_pasteboard (pboard))]];
+  [ns_pending_service_args addObject: [NSString 
stringWithLispString:ns_string_from_pasteboard (pboard)]];
 }
 
 
@@ -6291,8 +6290,8 @@ not_in_argv (NSString *arg)
 
   emacs_event->kind = NS_NONKEY_EVENT;
   emacs_event->code = KEY_NS_SPI_SERVICE_CALL;
-  ns_input_spi_name = build_string ([name UTF8String]);
-  ns_input_spi_arg = build_string ([arg UTF8String]);
+  ns_input_spi_name = [name lispString];
+  ns_input_spi_arg = [arg lispString];
   emacs_event->modifiers = EV_MODIFIERS (theEvent);
   EV_TRAILER (theEvent);
 
@@ -6374,7 +6373,7 @@ not_in_argv (NSString *arg)
 
       size = [newFont pointSize];
       ns_input_fontsize = make_fixnum (lrint (size));
-      ns_input_font = build_string ([[newFont familyName] UTF8String]);
+      ns_input_font = [[newFont familyName] lispString];
       EV_TRAILER (e);
     }
 }
@@ -6685,7 +6684,7 @@ not_in_argv (NSString *arg)
   processingCompose = YES;
   [workingText release];
   workingText = [str copy];
-  ns_working_text = build_string ([workingText UTF8String]);
+  ns_working_text = [workingText lispString];
 
   emacs_event->kind = NS_TEXT_EVENT;
   emacs_event->code = KEY_NS_PUT_WORKING_TEXT;
@@ -7605,7 +7604,7 @@ not_in_argv (NSString *arg)
   tem = f->icon_name;
   if (!NILP (tem))
     [win setMiniwindowTitle:
-           [NSString stringWithUTF8String: SSDATA (tem)]];
+           [NSString stringWithLispString:tem]];
 
   if (FRAME_PARENT_FRAME (f) != NULL)
     {
@@ -8609,7 +8608,7 @@ not_in_argv (NSString *arg)
 
       fenum = [files objectEnumerator];
       while ( (file = [fenum nextObject]) )
-        strings = Fcons (build_string ([file UTF8String]), strings);
+        strings = Fcons ([file lispString], strings);
     }
   else if ([type isEqualToString: NSURLPboardType])
     {
@@ -8618,7 +8617,7 @@ not_in_argv (NSString *arg)
 
       type_sym = Qurl;
 
-      strings = list1 (build_string ([[url absoluteString] UTF8String]));
+      strings = list1 ([[url absoluteString] lispString]);
     }
   else if ([type isEqualToString: NSStringPboardType]
            || [type isEqualToString: NSTabularTextPboardType])
@@ -8630,7 +8629,7 @@ not_in_argv (NSString *arg)
 
       type_sym = Qnil;
 
-      strings = list1 (build_string ([data UTF8String]));
+      strings = list1 ([data lispString]);
     }
   else
     {
@@ -8802,9 +8801,7 @@ not_in_argv (NSString *arg)
         }
       if (STRINGP (str))
         {
-          const char *utfStr = SSDATA (str);
-          NSString *nsStr = [NSString stringWithUTF8String: utfStr];
-          return nsStr;
+          return [NSString stringWithLispString:str];
         }
     }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]