Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
f55b79e6
Commit
f55b79e6
authored
Feb 18, 2003
by
Michael Beck
Browse files
Added new_id_from_str(), id_contains_char()
[r806]
parent
afc57ead
Changes
2
Hide whitespace changes
Inline
Side-by-side
ir/ident/ident.c
View file @
f55b79e6
...
...
@@ -43,10 +43,16 @@ void id_init(void)
INLINE
ident
*
id_from_str
(
const
char
*
str
,
int
len
)
{
assert
(
len
>
0
);
assert
(
len
>
0
);
return
set_hinsert0
(
id_set
,
str
,
len
,
ID_HASH
(
str
,
len
));
}
ident
*
new_id_from_str
(
const
char
*
str
)
{
assert
(
str
);
return
id_from_str
(
str
,
strlen
(
str
));
}
INLINE
const
char
*
id_to_str
(
ident
*
id
)
{
return
(
const
char
*
)
id
->
dptr
;
...
...
@@ -57,13 +63,13 @@ INLINE int id_to_strlen(ident *id)
return
id
->
size
;
}
int
id_is_prefix
(
ident
*
prefix
,
ident
*
id
)
int
id_is_prefix
(
ident
*
prefix
,
ident
*
id
)
{
if
(
id_to_strlen
(
prefix
)
>
id_to_strlen
(
id
))
return
0
;
return
0
==
memcmp
(
prefix
->
dptr
,
id
->
dptr
,
id_to_strlen
(
prefix
));
}
int
id_is_suffix
(
ident
*
suffix
,
ident
*
id
)
int
id_is_suffix
(
ident
*
suffix
,
ident
*
id
)
{
int
suflen
=
id_to_strlen
(
suffix
);
int
idlen
=
id_to_strlen
(
id
);
...
...
@@ -77,6 +83,11 @@ int id_is_suffix (ident *suffix, ident *id)
return
0
==
memcmp
(
suffix
->
dptr
,
part
,
suflen
);
}
int
id_contains_char
(
ident
*
id
,
char
c
)
{
return
strchr
(
id_to_str
(
id
),
c
)
!=
NULL
;
}
int
print_id
(
ident
*
id
)
{
return
xprintf
(
"%I"
,
id
);
...
...
ir/ident/ident.h
View file @
f55b79e6
...
...
@@ -45,14 +45,30 @@ typedef const struct set_entry ident;
* Store a string and create an ident.
*
* Stores a string in the ident module and returns a handle for the string.
* Copies the string.
*
* Copies the string. @p str must be zero terminated
*
* @param str - the string which shall be stored
*
* @return id - a handle for the generated ident
*
* @see id_to_str(), id_to_strlen()
*/
ident
*
new_id_from_str
(
const
char
*
str
);
/**
* Store a string and create an ident.
*
* Stores a string in the ident module and returns a handle for the string.
*
* Copies the string. This version can take non-zero-terminated strings
*
* @param str - the string (or whatever) which shall be stored
* @param len - the length of the data in bytes
*
* @return id - a handle for the generated ident
*
* @see id_to_str(), id_to_strlen()
* @see
new_
id_to_str(), id_to_strlen()
*/
INLINE
ident
*
id_from_str
(
const
char
*
str
,
int
len
);
...
...
@@ -66,7 +82,7 @@ INLINE ident *id_from_str (const char *str, int len);
*
* @return cp - a string
*
* @see id_from_str(), id_to_strlen()
* @see
new_id_to_str(),
id_from_str(), id_to_strlen()
*/
INLINE
const
char
*
id_to_str
(
ident
*
id
);
...
...
@@ -77,7 +93,7 @@ INLINE const char *id_to_str (ident *id);
*
* @return len - the length of the string
*
* @see id_from_str(), id_to_str()
* @see
new_id_to_str(),
id_from_str(), id_to_str()
*/
INLINE
int
id_to_strlen
(
ident
*
id
);
...
...
@@ -87,7 +103,7 @@ INLINE int id_to_strlen(ident *id);
* @param prefix - the prefix
* @param id - the ident
*
* @see id_from_str(), id_to_str(), id_is_prefix()
* @see
new_id_to_str(),
id_from_str(), id_to_str(), id_is_prefix()
*/
int
id_is_prefix
(
ident
*
prefix
,
ident
*
id
);
...
...
@@ -97,10 +113,20 @@ int id_is_prefix (ident *prefix, ident *id);
* @param suffix - the suffix
* @param id - the ident
*
* @see id_from_str(), id_to_str(), id_is_prefix()
* @see
new_id_to_str(),
id_from_str(), id_to_str(), id_is_prefix()
*/
int
id_is_suffix
(
ident
*
suffix
,
ident
*
id
);
/**
* Return true if an ident contains a given character.
*
* @param id - the ident
* @param c - the character
*
* @see new_id_to_str(), id_from_str(), id_to_str()
*/
int
id_contains_char
(
ident
*
id
,
char
c
);
/**
* Prints the ident to stdout.
*
...
...
@@ -109,7 +135,7 @@ int id_is_suffix (ident *suffix, ident *id);
* @return
* number of btes written
*
* @see id_from_str(), id_to_str(), id_is_prefix(), fprint_id()
* @see
new_id_to_str(),
id_from_str(), id_to_str(), id_is_prefix(), fprint_id()
*/
int
print_id
(
ident
*
id
);
...
...
@@ -122,7 +148,7 @@ int print_id (ident *id);
* @return
* number of btes written
*
* @see id_from_str(), id_to_str(), id_is_prefix(), print_id()
* @see
new_id_to_str(),
id_from_str(), id_to_str(), id_is_prefix(), print_id()
*/
int
fprint_id
(
FILE
*
F
,
ident
*
id
);
...
...
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