[Common-dev] CR-Client: common runtime strnstr&strnchr merged from HEAD to neptune116
Bob Clark bobclark at real.comSynopsis:
merge some optimizations from head over to hxclient_1_1_6_neptune
Overview:
In November we consolidated a couple separate strnchr and strnstr
implementations into one. They used to be implemented in
common/lang/xml and datatype/ram/fileformat. It simplified things to
add implementations to common/runtime.
Now it turns out that pulling this optimization over from head to
neptune116 we can fix some odd Mac runtime problems, where on some
versions of the OS the strnstr implementation in
datatype/ram/fileformat confuses a strnstr implementation in Apple's C
runtime. (That's why I'm interested in this now of all times.)
(The original change on head was discussed on the [hxclicore] list on
21 November 2003.)
Files Modified:
common/runtime/string.cpp
common/runtime/pub/hlxclib/string.h
common/lang/xml/pub/xmlesc.h
common/lang/xml/xmlesc.cpp
datatype/ram/fileformat/ramvsrc.cpp
--Bob
Index: string.cpp
===================================================================
RCS file: /cvsroot/common/runtime/string.cpp,v
retrieving revision 1.3
diff -u -w -r1.3 string.cpp
--- string.cpp 1 Apr 2003 21:10:40 -0000 1.3
+++ string.cpp 22 Mar 2004 21:39:16 -0000
@@ -90,3 +90,72 @@
return t*strtoul(s, end, base);
}
#endif
+
+/
*_______________________________________________________________________
____
+
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
+ * __helix_strnstr(sc, str, n)
+ *
+ * PARAMETERS:
+ * sc search string
+ * str string to be found
+ * n len of sc
+ *
+ * DESCRIPTION:
+ * finds a string in a string with a length restriction
+ *
+ * RETURNS
+ * points to position in sc of str. or NULL if not found
+
*_______________________________________________________________________
____
+
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
+const char*
+__helix_strnstr(const char* sc, const char* str, size_t n)
+{
+ if ( !sc || !*sc )
+ {
+ return NULL;
+ }
+ else if ( !str || !*str )
+ {
+ return sc;
+ }
+
+ size_t len = strlen(str);
+ for ( int i = 0; i < n && strlen(sc) > len; i++, sc++ )
+ {
+ if ( !strncmp(sc, str, len) )
+ {
+ return sc;
+ }
+ }
+ return NULL;
+}
+
+/
*_______________________________________________________________________
____
+
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
+ * __helix_strnchr(sc, str, n)
+ *
+ * PARAMETERS:
+ * sc search string
+ * c character to be found
+ * n len of sc
+ *
+ * DESCRIPTION:
+ * finds a character in a string with a length restriction
+ *
+ * RETURNS
+ * points to position in sc of c. or NULL if not found
+
*_______________________________________________________________________
____
+
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
+const char*
+__helix_strnchr(const char* sc, const char c, size_t n)
+{
+ for ( int i = 0; i < n && *sc; ++i, ++sc)
+ {
+ if ( *sc == c )
+ {
+ return sc;
+ }
+ }
+ return NULL;
+}
+
Index: pub/hlxclib/string.h
===================================================================
RCS file: /cvsroot/common/runtime/pub/hlxclib/string.h,v
retrieving revision 1.15
diff -u -w -r1.15 string.h
--- pub/hlxclib/string.h 10 Sep 2003 18:42:23 -0000 1.15
+++ pub/hlxclib/string.h 22 Mar 2004 21:39:16 -0000
@@ -72,9 +72,15 @@
void __helix_strlwr(char *s);
void __helix_strupr(char *s);
+const char* __helix_strnchr(const char* sc, const char c, size_t n);
+const char* __helix_strnstr(const char* sc, const char* str, size_t n);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
+
+#define strnchr __helix_strnchr
+#define strnstr __helix_strnstr
#ifdef _WINDOWS
HLX_INLINE int
Index: xmlesc.cpp
===================================================================
RCS file: /cvsroot/common/lang/xml/xmlesc.cpp,v
retrieving revision 1.7
diff -u -w -r1.7 xmlesc.cpp
--- xmlesc.cpp 2 Sep 2003 21:20:38 -0000 1.7
+++ xmlesc.cpp 22 Mar 2004 21:38:15 -0000
@@ -1565,76 +1565,3 @@
}
-/
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
- * Helper Functions
-
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
-/
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
- * strnstr(sc, str, n)
- *
- * PARAMETERS:
- * sc search string
- * str string to be found
- * n len of sc
- *
- * DESCRIPTION:
- * finds a string in a string with a length restriction
- *
- * RETURNS
- * points to position in sc of str. or NULL if not found
-
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
-const char*
-strnstr(const char* sc, const char* str, int n)
-{
- if ( !sc || !*sc )
- {
- return NULL;
- }
- else if ( !str || !*str )
- {
- return sc;
- }
-
- UINT32 len = strlen(str);
- for ( int i = 0; i < n && strlen(sc) > len; i++, sc++ )
- {
- if ( !strncmp(sc, str, len) )
- {
- return sc;
- }
- }
- return NULL;
-}
-
-/
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
- * strnchr(sc, str, n)
- *
- * PARAMETERS:
- * sc search string
- * c character to be found
- * n len of sc
- *
- * DESCRIPTION:
- * finds a character in a string with a length restriction
- *
- * RETURNS
- * points to position in sc of c. or NULL if not found
-
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
-const char*
-strnchr(const char* sc, const char c, int n)
-{
- char* p = NULL;
- for ( int i = 0; i < n && *sc; ++i, ++sc)
- {
- if ( *sc == c )
- {
- return sc;
- }
- }
- return NULL;
-}
Index: pub/xmlesc.h
===================================================================
RCS file: /cvsroot/common/lang/xml/pub/xmlesc.h,v
retrieving revision 1.4
diff -u -w -r1.4 xmlesc.h
--- pub/xmlesc.h 2 Sep 2003 21:20:38 -0000 1.4
+++ pub/xmlesc.h 22 Mar 2004 21:38:15 -0000
@@ -351,12 +351,4 @@
};
-/
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
- * Helper Functions
-
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
-const char* strnchr(const char* sc, const char c, int n);
-const char* strnstr(const char* sc, const char* str, int n);
-
#endif // _XMLCONV_H_
Index: ramvsrc.cpp
===================================================================
RCS file: /cvsroot/datatype/ram/fileformat/ramvsrc.cpp,v
retrieving revision 1.4
diff -u -w -r1.4 ramvsrc.cpp
--- ramvsrc.cpp 29 May 2003 14:41:38 -0000 1.4
+++ ramvsrc.cpp 22 Mar 2004 21:37:28 -0000
@@ -33,9 +33,6 @@
*
* ***** END LICENSE BLOCK ***** */
-const char* strnchr(const char* sc, const char c, int n);
-const char* strnstr(const char* sc, const char* str, int n);
-
#include <ctype.h>
#include "hxtypes.h"
#include "hxcom.h"
@@ -804,76 +801,3 @@
return HXR_OK;
}
-/
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
- * Helper Functions
-
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
-/
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
- * strnstr(sc, str, n)
- *
- * PARAMETERS:
- * sc search string
- * str string to be found
- * n len of sc
- *
- * DESCRIPTION:
- * finds a string in a string with a length restriction
- *
- * RETURNS
- * points to position in sc of str. or NULL if not found
-
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
-const char*
-strnstr(const char* sc, const char* str, int n)
-{
- if ( !sc || !*sc )
- {
- return NULL;
- }
- else if ( !str || !*str )
- {
- return sc;
- }
-
- UINT32 len = strlen(str);
- for ( int i = 0; i < n && strlen(sc) > len; i++, sc++ )
- {
- if ( !strncmp(sc, str, len) )
- {
- return sc;
- }
- }
- return NULL;
-}
-
-/
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
- * strnchr(sc, str, n)
- *
- * PARAMETERS:
- * sc search string
- * c character to be found
- * n len of sc
- *
- * DESCRIPTION:
- * finds a character in a string with a length restriction
- *
- * RETURNS
- * points to position in sc of c. or NULL if not found
-
*_______________________________________________________________________
____
-
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~*/
-const char*
-strnchr(const char* sc, const char c, int n)
-{
- char* p = NULL;
- for ( int i = 0; i < n && *sc; ++i, ++sc)
- {
- if ( *sc == c )
- {
- return sc;
- }
- }
- return NULL;
-}