Classes | Macros | Typedefs | Enumerations | Functions | Variables
lstrlib.c File Reference
#include "lprefix.h"
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
Include dependency graph for lstrlib.c:

Go to the source code of this file.

Classes

struct  cD
 
struct  GMatchState
 
struct  Header
 
struct  MatchState
 
struct  str_Writer
 

Macros

#define CAP_POSITION   (-2)
 
#define CAP_UNFINISHED   (-1)
 
#define L_ESC   '%'
 
#define L_FMTFLAGS   "-+ #0"
 
#define lstrlib_c
 
#define LUA_LIB
 
#define LUA_MAXCAPTURES   32
 
#define LUAL_PACKPADBYTE   0x00
 
#define MAX_FORMAT   32
 
#define MAX_ITEM   120
 
#define MAX_ITEMF   (110 + l_floatatt(MAX_10_EXP))
 
#define MAX_SIZET   ((size_t)(~(size_t)0))
 
#define MAXALIGN   (offsetof(struct cD, u))
 
#define MAXCCALLS   200
 
#define MAXINTSIZE   16
 
#define MAXSIZE   (sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX))
 
#define MC   ((1 << NB) - 1)
 
#define NB   CHAR_BIT
 
#define SPECIALS   "^$*+?.([%-"
 
#define SZINT   ((int)sizeof(lua_Integer))
 
#define uchar(c)   ((unsigned char)(c))
 

Typedefs

typedef struct GMatchState GMatchState
 
typedef struct Header Header
 
typedef enum KOption KOption
 
typedef struct MatchState MatchState
 

Enumerations

enum  KOption {
  Kint, Kuint, Kfloat, Knumber,
  Kdouble, Kchar, Kstring, Kzstr,
  Kpadding, Kpaddalign, Knop
}
 

Functions

static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, const char *e)
 
static int add_value (MatchState *ms, luaL_Buffer *b, const char *s, const char *e, int tr)
 
static void addlenmod (char *form, const char *lenmod)
 
static void addliteral (lua_State *L, luaL_Buffer *b, int arg)
 
static void addquoted (luaL_Buffer *b, const char *s, size_t len)
 
static int arith (lua_State *L, int op, const char *mtname)
 
static int arith_add (lua_State *L)
 
static int arith_div (lua_State *L)
 
static int arith_idiv (lua_State *L)
 
static int arith_mod (lua_State *L)
 
static int arith_mul (lua_State *L)
 
static int arith_pow (lua_State *L)
 
static int arith_sub (lua_State *L)
 
static int arith_unm (lua_State *L)
 
static int capture_to_close (MatchState *ms)
 
static int check_capture (MatchState *ms, int l)
 
static const char * classend (MatchState *ms, const char *p)
 
static void copywithendian (char *dest, const char *src, int size, int islittle)
 
static void createmetatable (lua_State *L)
 
static int digit (int c)
 
static const char * end_capture (MatchState *ms, const char *s, const char *p)
 
static size_t get_onecapture (MatchState *ms, int i, const char *s, const char *e, const char **cap)
 
static KOption getdetails (Header *h, size_t totalsize, const char **fmt, int *psize, int *ntoalign)
 
static size_t getendpos (lua_State *L, int arg, lua_Integer def, size_t len)
 
static int getnum (const char **fmt, int df)
 
static int getnumlimit (Header *h, const char **fmt, int df)
 
static KOption getoption (Header *h, const char **fmt, int *size)
 
static int gmatch (lua_State *L)
 
static int gmatch_aux (lua_State *L)
 
static void initheader (lua_State *L, Header *h)
 
static const char * lmemfind (const char *s1, size_t l1, const char *s2, size_t l2)
 
LUAMOD_API int luaopen_string (lua_State *L)
 
static const char * match (MatchState *ms, const char *s, const char *p)
 
static const char * match_capture (MatchState *ms, const char *s, int l)
 
static int match_class (int c, int cl)
 
static const char * matchbalance (MatchState *ms, const char *s, const char *p)
 
static int matchbracketclass (int c, const char *p, const char *ec)
 
static const char * max_expand (MatchState *ms, const char *s, const char *p, const char *ep)
 
static const char * min_expand (MatchState *ms, const char *s, const char *p, const char *ep)
 
static int nospecials (const char *p, size_t l)
 
static void packint (luaL_Buffer *b, lua_Unsigned n, int islittle, int size, int neg)
 
static size_t posrelatI (lua_Integer pos, size_t len)
 
static void prepstate (MatchState *ms, lua_State *L, const char *s, size_t ls, const char *p, size_t lp)
 
static int push_captures (MatchState *ms, const char *s, const char *e)
 
static void push_onecapture (MatchState *ms, int i, const char *s, const char *e)
 
static int quotefloat (lua_State *L, char *buff, lua_Number n)
 
static void reprepstate (MatchState *ms)
 
static const char * scanformat (lua_State *L, const char *strfrmt, char *form)
 
static int singlematch (MatchState *ms, const char *s, const char *p, const char *ep)
 
static const char * start_capture (MatchState *ms, const char *s, const char *p, int what)
 
static int str_byte (lua_State *L)
 
static int str_char (lua_State *L)
 
static int str_dump (lua_State *L)
 
static int str_find (lua_State *L)
 
static int str_find_aux (lua_State *L, int find)
 
static int str_format (lua_State *L)
 
static int str_gsub (lua_State *L)
 
static int str_len (lua_State *L)
 
static int str_lower (lua_State *L)
 
static int str_match (lua_State *L)
 
static int str_pack (lua_State *L)
 
static int str_packsize (lua_State *L)
 
static int str_rep (lua_State *L)
 
static int str_reverse (lua_State *L)
 
static int str_sub (lua_State *L)
 
static int str_unpack (lua_State *L)
 
static int str_upper (lua_State *L)
 
static int tonum (lua_State *L, int arg)
 
static void trymt (lua_State *L, const char *mtname)
 
static lua_Integer unpackint (lua_State *L, const char *str, int islittle, int size, int issigned)
 
static int writer (lua_State *L, const void *b, size_t size, void *ud)
 

Variables

union {
   int   dummy
 
   char   little
 
nativeendian = {1}
 
static const luaL_Reg stringmetamethods []
 
static const luaL_Reg strlib []
 

Macro Definition Documentation

◆ CAP_POSITION

#define CAP_POSITION   (-2)

Definition at line 355 of file lstrlib.c.

◆ CAP_UNFINISHED

#define CAP_UNFINISHED   (-1)

Definition at line 354 of file lstrlib.c.

◆ L_ESC

#define L_ESC   '%'

Definition at line 382 of file lstrlib.c.

◆ L_FMTFLAGS

#define L_FMTFLAGS   "-+ #0"

Definition at line 1094 of file lstrlib.c.

◆ lstrlib_c

#define lstrlib_c

Definition at line 7 of file lstrlib.c.

◆ LUA_LIB

#define LUA_LIB

Definition at line 8 of file lstrlib.c.

◆ LUA_MAXCAPTURES

#define LUA_MAXCAPTURES   32

Definition at line 35 of file lstrlib.c.

◆ LUAL_PACKPADBYTE

#define LUAL_PACKPADBYTE   0x00

Definition at line 1332 of file lstrlib.c.

◆ MAX_FORMAT

#define MAX_FORMAT   32

Definition at line 1101 of file lstrlib.c.

◆ MAX_ITEM

#define MAX_ITEM   120

Definition at line 1089 of file lstrlib.c.

◆ MAX_ITEMF

#define MAX_ITEMF   (110 + l_floatatt(MAX_10_EXP))

Definition at line 1078 of file lstrlib.c.

◆ MAX_SIZET

#define MAX_SIZET   ((size_t)(~(size_t)0))

Definition at line 47 of file lstrlib.c.

◆ MAXALIGN

#define MAXALIGN   (offsetof(struct cD, u))

Definition at line 1361 of file lstrlib.c.

◆ MAXCCALLS

#define MAXCCALLS   200

Definition at line 378 of file lstrlib.c.

◆ MAXINTSIZE

#define MAXINTSIZE   16

Definition at line 1336 of file lstrlib.c.

◆ MAXSIZE

#define MAXSIZE   (sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX))

Definition at line 49 of file lstrlib.c.

◆ MC

#define MC   ((1 << NB) - 1)

Definition at line 1342 of file lstrlib.c.

◆ NB

#define NB   CHAR_BIT

Definition at line 1339 of file lstrlib.c.

◆ SPECIALS

#define SPECIALS   "^$*+?.([%-"

Definition at line 383 of file lstrlib.c.

◆ SZINT

#define SZINT   ((int)sizeof(lua_Integer))

Definition at line 1345 of file lstrlib.c.

◆ uchar

#define uchar (   c)    ((unsigned char)(c))

Definition at line 40 of file lstrlib.c.

Typedef Documentation

◆ GMatchState

typedef struct GMatchState GMatchState

◆ Header

typedef struct Header Header

◆ KOption

typedef enum KOption KOption

◆ MatchState

typedef struct MatchState MatchState

Enumeration Type Documentation

◆ KOption

enum KOption
Enumerator
Kint 
Kuint 
Kfloat 
Knumber 
Kdouble 
Kchar 
Kstring 
Kzstr 
Kpadding 
Kpaddalign 
Knop 

Definition at line 1377 of file lstrlib.c.

Function Documentation

◆ add_s()

static void add_s ( MatchState ms,
luaL_Buffer b,
const char *  s,
const char *  e 
)
static

Definition at line 871 of file lstrlib.c.

◆ add_value()

static int add_value ( MatchState ms,
luaL_Buffer b,
const char *  s,
const char *  e,
int  tr 
)
static

Definition at line 906 of file lstrlib.c.

◆ addlenmod()

static void addlenmod ( char *  form,
const char *  lenmod 
)
static

Definition at line 1217 of file lstrlib.c.

◆ addliteral()

static void addliteral ( lua_State L,
luaL_Buffer b,
int  arg 
)
static

Definition at line 1157 of file lstrlib.c.

◆ addquoted()

static void addquoted ( luaL_Buffer b,
const char *  s,
size_t  len 
)
static

Definition at line 1104 of file lstrlib.c.

◆ arith()

static int arith ( lua_State L,
int  op,
const char *  mtname 
)
static

Definition at line 288 of file lstrlib.c.

◆ arith_add()

static int arith_add ( lua_State L)
static

Definition at line 297 of file lstrlib.c.

◆ arith_div()

static int arith_div ( lua_State L)
static

Definition at line 317 of file lstrlib.c.

◆ arith_idiv()

static int arith_idiv ( lua_State L)
static

Definition at line 321 of file lstrlib.c.

◆ arith_mod()

static int arith_mod ( lua_State L)
static

Definition at line 309 of file lstrlib.c.

◆ arith_mul()

static int arith_mul ( lua_State L)
static

Definition at line 305 of file lstrlib.c.

◆ arith_pow()

static int arith_pow ( lua_State L)
static

Definition at line 313 of file lstrlib.c.

◆ arith_sub()

static int arith_sub ( lua_State L)
static

Definition at line 301 of file lstrlib.c.

◆ arith_unm()

static int arith_unm ( lua_State L)
static

Definition at line 325 of file lstrlib.c.

◆ capture_to_close()

static int capture_to_close ( MatchState ms)
static

Definition at line 395 of file lstrlib.c.

◆ check_capture()

static int check_capture ( MatchState ms,
int  l 
)
static

Definition at line 386 of file lstrlib.c.

◆ classend()

static const char* classend ( MatchState ms,
const char *  p 
)
static

Definition at line 403 of file lstrlib.c.

◆ copywithendian()

static void copywithendian ( char *  dest,
const char *  src,
int  size,
int  islittle 
)
static

Definition at line 1532 of file lstrlib.c.

◆ createmetatable()

static void createmetatable ( lua_State L)
static

Definition at line 1795 of file lstrlib.c.

◆ digit()

static int digit ( int  c)
static

Definition at line 1396 of file lstrlib.c.

◆ end_capture()

static const char* end_capture ( MatchState ms,
const char *  s,
const char *  p 
)
static

Definition at line 548 of file lstrlib.c.

◆ get_onecapture()

static size_t get_onecapture ( MatchState ms,
int  i,
const char *  s,
const char *  e,
const char **  cap 
)
static

Definition at line 702 of file lstrlib.c.

◆ getdetails()

static KOption getdetails ( Header h,
size_t  totalsize,
const char **  fmt,
int *  psize,
int *  ntoalign 
)
static

Definition at line 1484 of file lstrlib.c.

◆ getendpos()

static size_t getendpos ( lua_State L,
int  arg,
lua_Integer  def,
size_t  len 
)
static

Definition at line 87 of file lstrlib.c.

◆ getnum()

static int getnum ( const char **  fmt,
int  df 
)
static

Definition at line 1398 of file lstrlib.c.

◆ getnumlimit()

static int getnumlimit ( Header h,
const char **  fmt,
int  df 
)
static

Definition at line 1415 of file lstrlib.c.

◆ getoption()

static KOption getoption ( Header h,
const char **  fmt,
int *  size 
)
static

Definition at line 1437 of file lstrlib.c.

◆ gmatch()

static int gmatch ( lua_State L)
static

Definition at line 854 of file lstrlib.c.

◆ gmatch_aux()

static int gmatch_aux ( lua_State L)
static

Definition at line 838 of file lstrlib.c.

◆ initheader()

static void initheader ( lua_State L,
Header h 
)
static

Definition at line 1427 of file lstrlib.c.

◆ lmemfind()

static const char* lmemfind ( const char *  s1,
size_t  l1,
const char *  s2,
size_t  l2 
)
static

Definition at line 673 of file lstrlib.c.

◆ luaopen_string()

LUAMOD_API int luaopen_string ( lua_State L)

Definition at line 1812 of file lstrlib.c.

◆ match()

static const char * match ( MatchState ms,
const char *  s,
const char *  p 
)
static

Definition at line 570 of file lstrlib.c.

◆ match_capture()

static const char* match_capture ( MatchState ms,
const char *  s,
int  l 
)
static

Definition at line 559 of file lstrlib.c.

◆ match_class()

static int match_class ( int  c,
int  cl 
)
static

Definition at line 427 of file lstrlib.c.

◆ matchbalance()

static const char* matchbalance ( MatchState ms,
const char *  s,
const char *  p 
)
static

Definition at line 486 of file lstrlib.c.

◆ matchbracketclass()

static int matchbracketclass ( int  c,
const char *  p,
const char *  ec 
)
static

Definition at line 447 of file lstrlib.c.

◆ max_expand()

static const char* max_expand ( MatchState ms,
const char *  s,
const char *  p,
const char *  ep 
)
static

Definition at line 506 of file lstrlib.c.

◆ min_expand()

static const char* min_expand ( MatchState ms,
const char *  s,
const char *  p,
const char *  ep 
)
static

Definition at line 521 of file lstrlib.c.

◆ nospecials()

static int nospecials ( const char *  p,
size_t  l 
)
static

Definition at line 746 of file lstrlib.c.

◆ packint()

static void packint ( luaL_Buffer b,
lua_Unsigned  n,
int  islittle,
int  size,
int  neg 
)
static

Definition at line 1511 of file lstrlib.c.

◆ posrelatI()

static size_t posrelatI ( lua_Integer  pos,
size_t  len 
)
static

Definition at line 71 of file lstrlib.c.

◆ prepstate()

static void prepstate ( MatchState ms,
lua_State L,
const char *  s,
size_t  ls,
const char *  p,
size_t  lp 
)
static

Definition at line 757 of file lstrlib.c.

◆ push_captures()

static int push_captures ( MatchState ms,
const char *  s,
const char *  e 
)
static

Definition at line 735 of file lstrlib.c.

◆ push_onecapture()

static void push_onecapture ( MatchState ms,
int  i,
const char *  s,
const char *  e 
)
static

Definition at line 725 of file lstrlib.c.

◆ quotefloat()

static int quotefloat ( lua_State L,
char *  buff,
lua_Number  n 
)
static

Definition at line 1133 of file lstrlib.c.

◆ reprepstate()

static void reprepstate ( MatchState ms)
static

Definition at line 767 of file lstrlib.c.

◆ scanformat()

static const char* scanformat ( lua_State L,
const char *  strfrmt,
char *  form 
)
static

Definition at line 1192 of file lstrlib.c.

◆ singlematch()

static int singlematch ( MatchState ms,
const char *  s,
const char *  p,
const char *  ep 
)
static

Definition at line 470 of file lstrlib.c.

◆ start_capture()

static const char* start_capture ( MatchState ms,
const char *  s,
const char *  p,
int  what 
)
static

Definition at line 534 of file lstrlib.c.

◆ str_byte()

static int str_byte ( lua_State L)
static

Definition at line 177 of file lstrlib.c.

◆ str_char()

static int str_char ( lua_State L)
static

Definition at line 195 of file lstrlib.c.

◆ str_dump()

static int str_dump ( lua_State L)
static

Definition at line 233 of file lstrlib.c.

◆ str_find()

static int str_find ( lua_State L)
static

Definition at line 819 of file lstrlib.c.

◆ str_find_aux()

static int str_find_aux ( lua_State L,
int  find 
)
static

Definition at line 773 of file lstrlib.c.

◆ str_format()

static int str_format ( lua_State L)
static

Definition at line 1227 of file lstrlib.c.

◆ str_gsub()

static int str_gsub ( lua_State L)
static

Definition at line 942 of file lstrlib.c.

◆ str_len()

static int str_len ( lua_State L)
static

Definition at line 55 of file lstrlib.c.

◆ str_lower()

static int str_lower ( lua_State L)
static

Definition at line 124 of file lstrlib.c.

◆ str_match()

static int str_match ( lua_State L)
static

Definition at line 824 of file lstrlib.c.

◆ str_pack()

static int str_pack ( lua_State L)
static

Definition at line 1544 of file lstrlib.c.

◆ str_packsize()

static int str_packsize ( lua_State L)
static

Definition at line 1643 of file lstrlib.c.

◆ str_rep()

static int str_rep ( lua_State L)
static

Definition at line 150 of file lstrlib.c.

◆ str_reverse()

static int str_reverse ( lua_State L)
static

Definition at line 112 of file lstrlib.c.

◆ str_sub()

static int str_sub ( lua_State L)
static

Definition at line 100 of file lstrlib.c.

◆ str_unpack()

static int str_unpack ( lua_State L)
static

Definition at line 1697 of file lstrlib.c.

◆ str_upper()

static int str_upper ( lua_State L)
static

Definition at line 137 of file lstrlib.c.

◆ tonum()

static int tonum ( lua_State L,
int  arg 
)
static

Definition at line 264 of file lstrlib.c.

◆ trymt()

static void trymt ( lua_State L,
const char *  mtname 
)
static

Definition at line 277 of file lstrlib.c.

◆ unpackint()

static lua_Integer unpackint ( lua_State L,
const char *  str,
int  islittle,
int  size,
int  issigned 
)
static

Definition at line 1671 of file lstrlib.c.

◆ writer()

static int writer ( lua_State L,
const void *  b,
size_t  size,
void *  ud 
)
static

Definition at line 222 of file lstrlib.c.

Variable Documentation

◆ dummy

int dummy

Definition at line 1350 of file lstrlib.c.

◆ little

char little

Definition at line 1351 of file lstrlib.c.

◆ nativeendian

const { ... } nativeendian

◆ stringmetamethods

const luaL_Reg stringmetamethods[]
static
Initial value:
= {
{"__add", arith_add},
{"__sub", arith_sub},
{"__mul", arith_mul},
{"__mod", arith_mod},
{"__pow", arith_pow},
{"__div", arith_div},
{"__idiv", arith_idiv},
{"__unm", arith_unm},
{"__index", NULL},
{NULL, NULL}
}

Definition at line 330 of file lstrlib.c.

◆ strlib

const luaL_Reg strlib[]
static
Initial value:
= {
{"byte", str_byte},
{"char", str_char},
{"dump", str_dump},
{"find", str_find},
{"format", str_format},
{"gmatch", gmatch},
{"gsub", str_gsub},
{"len", str_len},
{"lower", str_lower},
{"match", str_match},
{"rep", str_rep},
{"reverse", str_reverse},
{"sub", str_sub},
{"upper", str_upper},
{"pack", str_pack},
{"packsize", str_packsize},
{"unpack", str_unpack},
{NULL, NULL}
}

Definition at line 1773 of file lstrlib.c.

str_char
static int str_char(lua_State *L)
Definition: lstrlib.c:195
arith_idiv
static int arith_idiv(lua_State *L)
Definition: lstrlib.c:321
arith_add
static int arith_add(lua_State *L)
Definition: lstrlib.c:297
str_byte
static int str_byte(lua_State *L)
Definition: lstrlib.c:177
str_dump
static int str_dump(lua_State *L)
Definition: lstrlib.c:233
arith_div
static int arith_div(lua_State *L)
Definition: lstrlib.c:317
str_format
static int str_format(lua_State *L)
Definition: lstrlib.c:1227
arith_sub
static int arith_sub(lua_State *L)
Definition: lstrlib.c:301
str_match
static int str_match(lua_State *L)
Definition: lstrlib.c:824
str_gsub
static int str_gsub(lua_State *L)
Definition: lstrlib.c:942
str_find
static int str_find(lua_State *L)
Definition: lstrlib.c:819
arith_mod
static int arith_mod(lua_State *L)
Definition: lstrlib.c:309
arith_mul
static int arith_mul(lua_State *L)
Definition: lstrlib.c:305
arith_pow
static int arith_pow(lua_State *L)
Definition: lstrlib.c:313
str_unpack
static int str_unpack(lua_State *L)
Definition: lstrlib.c:1697
str_pack
static int str_pack(lua_State *L)
Definition: lstrlib.c:1544
str_packsize
static int str_packsize(lua_State *L)
Definition: lstrlib.c:1643
str_lower
static int str_lower(lua_State *L)
Definition: lstrlib.c:124
str_upper
static int str_upper(lua_State *L)
Definition: lstrlib.c:137
str_len
static int str_len(lua_State *L)
Definition: lstrlib.c:55
gmatch
static int gmatch(lua_State *L)
Definition: lstrlib.c:854
str_reverse
static int str_reverse(lua_State *L)
Definition: lstrlib.c:112
str_sub
static int str_sub(lua_State *L)
Definition: lstrlib.c:100
arith_unm
static int arith_unm(lua_State *L)
Definition: lstrlib.c:325
str_rep
static int str_rep(lua_State *L)
Definition: lstrlib.c:150


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:28