1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include "atoi.h"
- UA_StatusCode atoiUnsigned(const char *s, size_t size, UA_UInt64 *result){
- if(size < 1){
- return UA_STATUSCODE_BADDECODINGERROR;
- }
-
- size_t i = 0;
- UA_UInt64 n = 0;
-
- while ( i < size) {
-
- if ( s[i] >= '0' && s[i] <= '9' )
- {
- n *= 10;
- n = (n + (UA_UInt64)(s[i] - '0'));
- i++;
- }else{
- return UA_STATUSCODE_BADDECODINGERROR;
- }
- }
-
- *result = n;
- return UA_STATUSCODE_GOOD;
- }
- UA_StatusCode atoiSigned(const char *s, size_t size, UA_Int64 *result){
- if(size < 1){
- return UA_STATUSCODE_BADDECODINGERROR;
- }
-
- size_t i = 0;
- UA_Int64 n = 0;
- UA_Boolean neg = 0;
-
- if(*s == '-'){
- neg = 1;
- i++;
- }
- while ( i < size) {
- if ( s[i] >= '0' && s[i] <= '9' )
- {
- n *= 10;
- n = (n + (s[i] - '0'));
- i++;
- }else{
- return UA_STATUSCODE_BADDECODINGERROR;
- }
- }
-
- if (neg){
- n *= -1;
- }
-
- *result = n;
- return UA_STATUSCODE_GOOD;
- }
|