lj_strscan.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. ** String scanning.
  3. ** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #ifndef _LJ_STRSCAN_H
  6. #define _LJ_STRSCAN_H
  7. #include "lj_obj.h"
  8. /* Options for accepted/returned formats. */
  9. #define STRSCAN_OPT_TOINT 0x01 /* Convert to int32_t, if possible. */
  10. #define STRSCAN_OPT_TONUM 0x02 /* Always convert to double. */
  11. #define STRSCAN_OPT_IMAG 0x04
  12. #define STRSCAN_OPT_LL 0x08
  13. #define STRSCAN_OPT_C 0x10
  14. /* Returned format. */
  15. typedef enum {
  16. STRSCAN_ERROR,
  17. STRSCAN_NUM, STRSCAN_IMAG,
  18. STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64,
  19. } StrScanFmt;
  20. LJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o,
  21. uint32_t opt);
  22. LJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o);
  23. #if LJ_DUALNUM
  24. LJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o);
  25. #else
  26. #define lj_strscan_number(s, o) lj_strscan_num((s), (o))
  27. #endif
  28. /* Check for number or convert string to number/int in-place (!). */
  29. static LJ_AINLINE int lj_strscan_numberobj(TValue *o)
  30. {
  31. return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o));
  32. }
  33. #endif