mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
lib/util: Make string_replace from s3 common
The s4 implementation didn't do multibyte strings, so was only good for '/' which is known to be safe in all multibyte charsets. Andrew Bartlett Signed-off-by: Andrew Tridgell <tridge@samba.org>
This commit is contained in:
parent
b2e37d9ce1
commit
17ccff973a
@ -249,13 +249,3 @@ _PUBLIC_ bool strequal(const char *s1, const char *s2)
|
||||
return strcasecmp(s1,s2) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
String replace.
|
||||
**/
|
||||
_PUBLIC_ void string_replace(char *s, char oldc, char newc)
|
||||
{
|
||||
while (*s) {
|
||||
if (*s == oldc) *s = newc;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
@ -59,3 +59,46 @@ _PUBLIC_ size_t ucs2_align(const void *base_ptr, const void *p, int flags)
|
||||
return 0;
|
||||
return PTR_DIFF(p, base_ptr) & 1;
|
||||
}
|
||||
|
||||
/**
|
||||
String replace.
|
||||
NOTE: oldc and newc must be 7 bit characters
|
||||
**/
|
||||
void string_replace( char *s, char oldc, char newc )
|
||||
{
|
||||
char *p;
|
||||
|
||||
/* this is quite a common operation, so we want it to be
|
||||
fast. We optimise for the ascii case, knowing that all our
|
||||
supported multi-byte character sets are ascii-compatible
|
||||
(ie. they match for the first 128 chars) */
|
||||
|
||||
for (p = s; *p; p++) {
|
||||
if (*p & 0x80) /* mb string - slow path. */
|
||||
break;
|
||||
if (*p == oldc) {
|
||||
*p = newc;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*p)
|
||||
return;
|
||||
|
||||
/* Slow (mb) path. */
|
||||
#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
|
||||
/* With compose characters we must restart from the beginning. JRA. */
|
||||
p = s;
|
||||
#endif
|
||||
|
||||
while (*p) {
|
||||
size_t c_size;
|
||||
next_codepoint(p, &c_size);
|
||||
|
||||
if (c_size == 1) {
|
||||
if (*p == oldc) {
|
||||
*p = newc;
|
||||
}
|
||||
}
|
||||
p += c_size;
|
||||
}
|
||||
}
|
||||
|
@ -233,49 +233,6 @@ bool strisnormal(const char *s, int case_default)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
String replace.
|
||||
NOTE: oldc and newc must be 7 bit characters
|
||||
**/
|
||||
void string_replace( char *s, char oldc, char newc )
|
||||
{
|
||||
char *p;
|
||||
|
||||
/* this is quite a common operation, so we want it to be
|
||||
fast. We optimise for the ascii case, knowing that all our
|
||||
supported multi-byte character sets are ascii-compatible
|
||||
(ie. they match for the first 128 chars) */
|
||||
|
||||
for (p = s; *p; p++) {
|
||||
if (*p & 0x80) /* mb string - slow path. */
|
||||
break;
|
||||
if (*p == oldc) {
|
||||
*p = newc;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*p)
|
||||
return;
|
||||
|
||||
/* Slow (mb) path. */
|
||||
#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
|
||||
/* With compose characters we must restart from the beginning. JRA. */
|
||||
p = s;
|
||||
#endif
|
||||
|
||||
while (*p) {
|
||||
size_t c_size;
|
||||
next_codepoint(p, &c_size);
|
||||
|
||||
if (c_size == 1) {
|
||||
if (*p == oldc) {
|
||||
*p = newc;
|
||||
}
|
||||
}
|
||||
p += c_size;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip past some strings in a buffer - old version - no checks.
|
||||
* **/
|
||||
|
Loading…
Reference in New Issue
Block a user