📄 tc_strtol.c
字号:
/* *---------------------------------------------------------------------- * T-Kernel / Standard Extension * * Copyright (C) 2006 by Ken Sakamura. All rights reserved. * T-Kernel / Standard Extension is distributed * under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * * Version: 1.00.00 * Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* * tc_strtol.C (libtcstr) * * base == 0 : +/-<decimal> | +/-0<octal> | +/-0X<hexadecimal> | +/-0x<hexadecimal> * base == 16 : +/-<hexadecimal> | +/-0X<hexadecimal> | +/-0x<hexadecimal> * Other : +/-<base n> * (base <= 36) * * The first space is skipped. * If ps != NULL, a pointer to the next string is set. */#include <basic.h>#include <tcode.h>#define TSD_TST_VAL_8 8#define TSD_TST_VAL_9 9#define TSD_TST_VAL_10 10#define TSD_TST_VAL_16 16long tc_strtol(const TC *str, TC **ptr, int base){ W n; W sign = 0; long val = 0; while ((*str == TK_KSP )||( *str == '\t')) { str++; } if (*str == TK_MINS) { sign++; str++; } else if ( *str == TK_PLUS) { str++; } if (base <= 1) { base = TSD_TST_VAL_10; if (*(str++) == TK_0) { base = TSD_TST_VAL_8; if ((*str == TK_X )||( *str == TK_x)) { base = TSD_TST_VAL_16; } } str--; } if (base <= TSD_TST_VAL_10 ) { while (((n = *(str++) - TK_0) >= 0) && (n < base)) { val = (val * base) + n; } } else { if (base == TSD_TST_VAL_16) { if ((*(str++) == TK_0) && ((*str == TK_X )||( *str == TK_x))) { str++; } else { str--; } } while ((n = *(str++) - TK_0) >= 0) { if (n > TSD_TST_VAL_9) { n -= (TK_A - TK_0); if (n < 0) { break; } if ( n >= (TK_a - TK_A)) { n -= (TK_a - TK_A); } n += TSD_TST_VAL_10; if ( n >= base) { break; } } val = (val * base) + n; } } if (ptr != 0) { *ptr = (TC *) (str - 1); } return (sign != 0) ? -val : val;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -