Native_Functions: Add f_str_to{lower,upper}()
TTCN-3 interestingly doens't seem to have any case-insensitive string matching or functions to convert to uppwer/lowercase. Change-Id: I2e6e0fd2da001a3cc6d9c31c9e766ae54bf17b2f
This commit is contained in:
parent
8aefd11dd2
commit
625faadb76
|
@ -16,6 +16,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <Charstring.hh>
|
||||
#include <Octetstring.hh>
|
||||
|
@ -75,5 +76,34 @@ CHARSTRING f__inet__hntoa(const OCTETSTRING& in)
|
|||
return CHARSTRING(str);
|
||||
}
|
||||
|
||||
CHARSTRING f__str__tolower(const CHARSTRING& in)
|
||||
{
|
||||
TTCN_Buffer ttcn_buffer(in);
|
||||
TTCN_Buffer buf_out;
|
||||
CHARSTRING out;
|
||||
unsigned int i;
|
||||
|
||||
const char *in_str = (const char *)ttcn_buffer.get_data();
|
||||
for (i = 0; i < strlen(in_str); i++)
|
||||
buf_out.put_c((unsigned char) tolower(in_str[i]));
|
||||
buf_out.get_string(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
CHARSTRING f__str__toupper(const CHARSTRING& in)
|
||||
{
|
||||
TTCN_Buffer ttcn_buffer(in);
|
||||
TTCN_Buffer buf_out;
|
||||
CHARSTRING out;
|
||||
unsigned int i;
|
||||
|
||||
const char *in_str = (const char *)ttcn_buffer.get_data();
|
||||
for (i = 0; i < strlen(in_str); i++)
|
||||
buf_out.put_c((unsigned char) toupper(in_str[i]));
|
||||
buf_out.get_string(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -11,4 +11,10 @@ module Native_Functions {
|
|||
external function f_inet_ntoa(in octetstring oct) return charstring;
|
||||
/* like inet_ntoa() but input is host byte order */
|
||||
external function f_inet_hntoa(in octetstring oct) return charstring;
|
||||
|
||||
/* convert content of charstring to lower-case using tolower(3) */
|
||||
external function f_str_tolower(in charstring input) return charstring;
|
||||
|
||||
/* convert content of charstring to upper-case using toupper(3) */
|
||||
external function f_str_toupper(in charstring input) return charstring;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue