Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
f095cc95
Commit
f095cc95
authored
Jul 07, 2018
by
LEFEBVREJP email
Browse files
Merge branch 'ordinal' into 'master'
Ordinal See merge request
!43
parents
521219ba
43da4b87
Pipeline
#14002
passed with stages
in 7 minutes and 47 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
radixcore/stringfunctions.cc
View file @
f095cc95
...
...
@@ -142,4 +142,6 @@ struct std::tm utc_to_time(const std::string &time, int &zone, int &daylight)
return
res
;
}
int
ordinal
(
char
c
)
{
return
(
unsigned
char
)
c
;
}
}
// namespace radix
radixcore/stringfunctions.hh
View file @
f095cc95
...
...
@@ -17,6 +17,21 @@
namespace
radix
{
/**
* @brief ordinal convert character to its ordinal value
* @param c char
* @return integer
*/
int
RADIX_PUBLIC
ordinal
(
char
c
);
/**
* @brief itoa converts integer into character
* @param number integer must be within character bounds
* @return char
*/
template
<
typename
type
=
int
>
char
RADIX_PUBLIC
itoa
(
type
number
);
/**
* @brief utc_to_time UTC time to
* @param time UTC formatted date and time
...
...
radixcore/stringfunctions.i.hh
View file @
f095cc95
...
...
@@ -33,4 +33,16 @@ std::string join(const std::string &delim, const T &x)
}
return
ss
.
str
();
}
template
<
typename
type
>
char
itoa
(
type
number
)
{
char
c
[
2
];
c
[
0
]
=
'0'
;
c
[
1
]
=
'\0'
;
// null
if
(
number
>
type
(
255
))
return
c
[
0
];
if
(
number
<
type
(
0
))
return
c
[
0
];
sprintf
(
c
,
"%c"
,
number
);
return
c
[
0
];
}
}
// namespace radix
radixcore/tests/tstString.cc
View file @
f095cc95
...
...
@@ -104,3 +104,36 @@ TEST(Split, NoDelim)
ASSERT_EQ
(
1
,
x
.
size
());
EXPECT_EQ
(
"nope"
,
x
[
0
]);
}
TEST
(
Radix
,
OrdinalItoa
)
{
{
char
c
=
itoa
(
127
);
EXPECT_EQ
(
'\x7F'
,
c
);
int
i
=
ordinal
(
c
);
EXPECT_EQ
(
127
,
i
);
}
{
char
c
=
itoa
(
0
);
// null
EXPECT_EQ
(
'\0'
,
c
);
int
i
=
ordinal
(
c
);
EXPECT_EQ
(
0
,
i
);
}
{
char
c
=
itoa
(
99
);
EXPECT_EQ
(
'c'
,
c
);
int
i
=
ordinal
(
c
);
EXPECT_EQ
(
99
,
i
);
}
{
char
c
=
itoa
(
48
);
EXPECT_EQ
(
'0'
,
c
);
int
i
=
ordinal
(
c
);
EXPECT_EQ
(
48
,
i
);
}
{
char
c
=
itoa
(
140
);
EXPECT_EQ
(
'\x8C'
,
c
);
int
i
=
ordinal
(
c
);
EXPECT_EQ
(
140
,
i
);
}
}
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