2 libc-extension.cc -- implement some string.h extensions
4 source file of the flowerlib
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
11 #include "libc-extension.hh"
14 compensate for lacking libc functions.
17 strnlwr( char* start_l ,int n)
19 char * p = start_l + n;
20 while ( --p >= start_l) {
21 *p = tolower( *p ); /* a macro on some compilers */
27 strnupr( char* start_l, int n)
29 char * p = start_l + n;
30 while ( --p >= start_l) {
31 *p = toupper( *p ); /* a macro on some compilers */
36 /** locate a substring. #memmem# finds the first occurrence of
37 #needle# in #haystack#
41 memmem(const Byte * haystack, const Byte *needle,
42 int haystack_len, int needle_len)
44 const Byte * end_haystack = haystack + haystack_len - needle_len;
45 const Byte * end_needle = needle + needle_len ;
47 /* Ahhh ... Some minimal lowlevel stuff. This *is* nice; Varation
48 is the spice of life */
49 while (haystack < end_haystack) {
50 const Byte *subneedle_l = needle;
51 const Byte *subhaystack_l = haystack;
52 while (subneedle_l < end_needle) {
53 if (*subneedle_l++ != *subhaystack_l++)
54 goto next; // yeah. I should be prosecuted.
57 // completed the needle. Gotcha.
58 return (char*) haystack;
66 memrchr(const Byte * p, int n, char c)
79 my_swap(T &t1, T &t2, T &tmp)
87 strrev( Byte* byte_l, int length_i )
91 Byte* left_l = byte_l;
92 Byte* right_l = byte_l + length_i;
94 while ( right_l > left_l ) {
95 my_swap(*right_l-- , *left_l++ , tmp_byte);