Back to index

plt-scheme  4.2.1
String.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: string copy and conversion
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #define  Uses_wxObject
00028 #include "wx.h"
00029 
00030 #include <string.h>
00031 
00032 #ifdef _AIX41
00033 # include <strings.h>
00034 #endif
00035 
00036 char *copystring(const char *s)
00037 {
00038   size_t len;
00039   char *news;
00040 
00041   if (s == NULL) s = "";
00042   len = strlen (s) + 1;
00043   news = new WXGC_ATOMIC char[len];
00044   memcpy(news, s, len);        // Should be the fastest
00045   return news;
00046 }
00047 
00048 #ifdef MZ_PRECISE_GC
00049 char *copystring_to_aligned(const char *s, int d)
00050 {
00051   size_t len;
00052   char *news;
00053 
00054   len = strlen(s XFORM_OK_PLUS d);
00055   news = new WXGC_ATOMIC char[len + 1];
00056   memcpy(news, s + d, len + 1);
00057   return news;
00058 }
00059 #endif
00060 
00061 void wxGetLabelAndKey(char *label, char **clean_label, char **clean_key)
00062 {
00063     char *key, *s;
00064 
00065     s = copystring(label); // make private copy
00066     *clean_label = s;
00067 #if 0
00068     char *amp;
00069     if ((amp = strchr(*clean_label, '&'))) { // is there an ampersand? -> erase
00070        memmove(amp, amp+1, strlen(amp+1) + 1);
00071     }
00072 #endif
00073     if ((key=strchr(*clean_label, '\t'))) // is there a key binding? -> split
00074        *key++ ='\0';
00075     if (clean_key)
00076       *clean_key = key; // point to key binding in private copy
00077 }