Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LSH
lsh
Commits
f8d92255
Commit
f8d92255
authored
Apr 03, 2002
by
Pontus Freyhult
Browse files
Added lsh_string_colonize to insert colons in a lsh_string.
Rev: src/format.c:1.45 Rev: src/format.h:1.36
parent
d537b654
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/format.c
View file @
f8d92255
...
...
@@ -631,3 +631,38 @@ lsh_string_prefixp(const struct lsh_string *prefix,
return
(
(
prefix
->
length
<=
s
->
length
)
&&
!
memcmp
(
prefix
->
data
,
s
->
data
,
prefix
->
length
));
}
struct
lsh_string
*
lsh_string_colonize
(
struct
lsh_string
*
s
,
int
every
,
int
freeflag
)
{
UINT32
i
=
0
;
UINT32
j
=
0
;
struct
lsh_string
*
packet
;
UINT32
length
;
int
colons
;
/* No of colonds depens on length, 0..every => 0,
* every..2*every => 1 */
colons
=
s
->
length
?
(
s
->
length
-
1
)
/
every
:
0
;
length
=
s
->
length
+
colons
;
packet
=
lsh_string_alloc
(
length
);
for
(;
i
<
s
->
length
;
i
++
)
{
assert
(
j
<
length
);
/* Extra sanity check */
if
(
i
&&
!
(
i
%
every
))
/* Every nth position except at the beginning */
packet
->
data
[
j
++
]
=
':'
;
assert
(
j
<
length
);
/* Extra sanity check */
packet
->
data
[
j
++
]
=
s
->
data
[
i
];
}
if
(
freeflag
)
/* Throw away the source string? */
lsh_string_free
(
s
);
return
packet
;
}
src/format.h
View file @
f8d92255
...
...
@@ -106,4 +106,7 @@ int lsh_string_eq_l(const struct lsh_string *a, UINT32 length, const UINT8 *b);
int
lsh_string_prefixp
(
const
struct
lsh_string
*
prefix
,
const
struct
lsh_string
*
s
);
struct
lsh_string
*
lsh_string_colonize
(
struct
lsh_string
*
s
,
int
every
,
int
freeflag
);
#endif
/* LSH_FORMAT_H_INCLUDED */
Write
Preview
Supports
Markdown
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