Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
1fe034de
Commit
1fe034de
authored
Mar 10, 2006
by
osku
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port parts of r211 from branches/fts:
Add ut_strcount() and ut_strreplace().
parent
28215726
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
0 deletions
+117
-0
include/ut0mem.h
include/ut0mem.h
+24
-0
ut/ut0mem.c
ut/ut0mem.c
+93
-0
No files found.
include/ut0mem.h
View file @
1fe034de
...
...
@@ -181,6 +181,30 @@ ut_memcpyq(
const
char
*
src
,
/* in: string to be quoted */
ulint
len
);
/* in: length of src */
/**************************************************************************
Return the number of times s2 occurs in s1. Overlapping instances of s2
are only counted once. */
ulint
ut_strcount
(
/*========*/
/* out: the number of times s2 occurs in s1 */
const
char
*
s1
,
/* in: string to search in */
const
char
*
s2
);
/* in: string to search for */
/**************************************************************************
Replace every occurrence of s1 in str with s2. Overlapping instances of s1
are only replaced once. */
char
*
ut_strreplace
(
/*==========*/
/* out, own: modified string, must be
freed with mem_free() */
const
char
*
str
,
/* in: string to operate on */
const
char
*
s1
,
/* in: string to replace */
const
char
*
s2
);
/* in: string to replace s1 with */
#ifndef UNIV_NONINL
#include "ut0mem.ic"
#endif
...
...
ut/ut0mem.c
View file @
1fe034de
...
...
@@ -437,3 +437,96 @@ ut_memcpyq(
return
(
dest
);
}
/**************************************************************************
Return the number of times s2 occurs in s1. Overlapping instances of s2
are only counted once. */
ulint
ut_strcount
(
/*========*/
/* out: the number of times s2 occurs in s1 */
const
char
*
s1
,
/* in: string to search in */
const
char
*
s2
)
/* in: string to search for */
{
ulint
count
=
0
;
ulint
len
=
strlen
(
s2
);
if
(
len
==
0
)
{
return
(
0
);
}
for
(;;)
{
s1
=
strstr
(
s1
,
s2
);
if
(
!
s1
)
{
break
;
}
count
++
;
s1
+=
len
;
}
return
(
count
);
}
/**************************************************************************
Replace every occurrence of s1 in str with s2. Overlapping instances of s1
are only replaced once. */
char
*
ut_strreplace
(
/*==========*/
/* out, own: modified string, must be
freed with mem_free() */
const
char
*
str
,
/* in: string to operate on */
const
char
*
s1
,
/* in: string to replace */
const
char
*
s2
)
/* in: string to replace s1 with */
{
char
*
new_str
;
char
*
ptr
;
const
char
*
str_end
;
ulint
str_len
=
strlen
(
str
);
ulint
s1_len
=
strlen
(
s1
);
ulint
s2_len
=
strlen
(
s2
);
ulint
count
=
0
;
int
len_delta
=
(
int
)
s2_len
-
(
int
)
s1_len
;
str_end
=
str
+
str_len
;
if
(
len_delta
<=
0
)
{
len_delta
=
0
;
}
else
{
count
=
ut_strcount
(
str
,
s1
);
}
new_str
=
mem_alloc
(
str_len
+
count
*
len_delta
+
1
);
ptr
=
new_str
;
while
(
str
)
{
const
char
*
next
=
strstr
(
str
,
s1
);
if
(
!
next
)
{
next
=
str_end
;
}
memcpy
(
ptr
,
str
,
next
-
str
);
ptr
+=
next
-
str
;
if
(
next
==
str_end
)
{
break
;
}
memcpy
(
ptr
,
s2
,
s2_len
);
ptr
+=
s2_len
;
str
=
next
+
s1_len
;
}
*
ptr
=
'\0'
;
return
(
new_str
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment