github.com/gotranspile/cxgo@v0.3.8-0.20240118201721-29871598a6a2/libs/string.go (about) 1 package libs 2 3 import ( 4 "github.com/gotranspile/cxgo/runtime/libc" 5 "github.com/gotranspile/cxgo/types" 6 ) 7 8 // https://pubs.opengroup.org/onlinepubs/9699919799/ 9 10 const ( 11 stringH = "string.h" 12 ) 13 14 func init() { 15 // TODO: should include <locale.h> 16 RegisterLibrary(stringH, func(c *Env) *Library { 17 gintT := c.Go().Int() 18 voidP := c.PtrT(nil) 19 cstrT := c.C().String() 20 return &Library{ 21 Imports: map[string]string{ 22 "libc": RuntimeLibc, 23 }, 24 Idents: map[string]*types.Ident{ 25 "memcmp": c.NewIdent("memcmp", "libc.MemCmp", libc.MemCmp, c.FuncTT(gintT, voidP, voidP, gintT)), 26 "memchr": c.NewIdent("memchr", "libc.MemChr", libc.MemChr, c.FuncTT(cstrT, cstrT, c.Go().Byte(), gintT)), 27 "strlen": c.NewIdent("strlen", "libc.StrLen", libc.StrLen, c.FuncTT(gintT, cstrT)), 28 "strchr": c.NewIdent("strchr", "libc.StrChr", libc.StrChr, c.FuncTT(cstrT, cstrT, c.Go().Byte())), 29 "strrchr": c.NewIdent("strrchr", "libc.StrRChr", libc.StrRChr, c.FuncTT(cstrT, cstrT, c.Go().Byte())), 30 "strstr": c.NewIdent("strstr", "libc.StrStr", libc.StrStr, c.FuncTT(cstrT, cstrT, cstrT)), 31 "strcmp": c.NewIdent("strcmp", "libc.StrCmp", libc.StrCmp, c.FuncTT(gintT, cstrT, cstrT)), 32 "strncmp": c.NewIdent("strncmp", "libc.StrNCmp", libc.StrNCmp, c.FuncTT(gintT, cstrT, cstrT, gintT)), 33 "strcasecmp": c.NewIdent("strcasecmp", "libc.StrCaseCmp", libc.StrCaseCmp, c.FuncTT(gintT, cstrT, cstrT)), 34 "strncasecmp": c.NewIdent("strncasecmp", "libc.StrNCaseCmp", libc.StrNCaseCmp, c.FuncTT(gintT, cstrT, cstrT, gintT)), 35 "strcpy": c.NewIdent("strcpy", "libc.StrCpy", libc.StrCpy, c.FuncTT(cstrT, cstrT, cstrT)), 36 "strncpy": c.NewIdent("strncpy", "libc.StrNCpy", libc.StrNCpy, c.FuncTT(cstrT, cstrT, cstrT, gintT)), 37 "strcat": c.NewIdent("strcat", "libc.StrCat", libc.StrCat, c.FuncTT(cstrT, cstrT, cstrT)), 38 "strncat": c.NewIdent("strncat", "libc.StrNCat", libc.StrNCat, c.FuncTT(cstrT, cstrT, cstrT, gintT)), 39 "strtok": c.NewIdent("strtok", "libc.StrTok", libc.StrTok, c.FuncTT(cstrT, cstrT, cstrT)), 40 "strspn": c.NewIdent("strspn", "libc.StrSpn", libc.StrSpn, c.FuncTT(gintT, cstrT, cstrT)), 41 "strcspn": c.NewIdent("strcspn", "libc.StrCSpn", libc.StrCSpn, c.FuncTT(gintT, cstrT, cstrT)), 42 }, 43 } 44 }) 45 }