p2  0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
string.c File Reference

internals of utf-8 and byte strings More...

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "p2.h"
#include "internal.h"
#include "khash.h"
#include "table.h"
+ Include dependency graph for string.c:

Go to the source code of this file.

Macros

#define BYTES_FACTOR   1 / 8 * 9
 
#define BYTES_CHUNK   32
 
#define BYTES_ALIGN(len)   PN_ALIGN(len + sizeof(struct PNBytes), BYTES_CHUNK) - sizeof(struct PNBytes)
 

Functions

void potion_add_str (Potion *P, PN s)
 
PN potion_lookup_str (Potion *P, const char *str)
 
PN potion_str (Potion *P, const char *str)
 
PN potion_str2 (Potion *P, char *str, size_t len)
 
PN potion_strcat (Potion *P, char *str, char *str2)
 
PN potion_str_format (Potion *P, const char *format,...)
 
static size_t potion_utf8char_offset (const char *s, size_t index)
 returns byte position of the index-th utf8 char More...
 
static size_t potion_utf8char_nextchar (const char *s, size_t offset)
 returns byte position of next utf8 char after s[offset] More...
 
static unsigned long potion_utf8char_decode (const char *s)
 decode the utf8 codepoint at s, i.e. ord More...
 
static PN potion_str_slice_index (PN index, size_t len, int nilvalue)
 helper function for potion_str_slice to fix index. More...
 
PN potion_byte_str (Potion *P, const char *str)
 
PN potion_byte_str2 (Potion *P, const char *str, size_t len)
 
PN potion_bytes (Potion *P, size_t len)
 
PN_SIZE pn_printf (Potion *P, PN bytes, const char *format,...)
 
void potion_bytes_obj_string (Potion *P, PN bytes, PN obj)
 
void potion_str_hash_init (Potion *P)
 
void potion_str_init (Potion *P)
 

Variables

static const uint8_t utf8d []
 

Detailed Description

internals of utf-8 and byte strings

See also
PNString class members
PNBytes class members

Definition in file string.c.

Macro Definition Documentation

#define BYTES_FACTOR   1 / 8 * 9

Definition at line 16 of file string.c.

#define BYTES_CHUNK   32

Definition at line 17 of file string.c.

#define BYTES_ALIGN (   len)    PN_ALIGN(len + sizeof(struct PNBytes), BYTES_CHUNK) - sizeof(struct PNBytes)

Definition at line 18 of file string.c.

Function Documentation

void potion_add_str ( Potion P,
PN  s 
)

Definition at line 20 of file string.c.

PN potion_lookup_str ( Potion P,
const char *  str 
)

Definition at line 26 of file string.c.

PN potion_str ( Potion P,
const char *  str 
)

Definition at line 33 of file string.c.

PN potion_str2 ( Potion P,
char *  str,
size_t  len 
)

Definition at line 47 of file string.c.

PN potion_strcat ( Potion P,
char *  str,
char *  str2 
)

Definition at line 64 of file string.c.

PN potion_str_format ( Potion P,
const char *  format,
  ... 
)

Definition at line 81 of file string.c.

static size_t potion_utf8char_offset ( const char *  s,
size_t  index 
)
static

returns byte position of the index-th utf8 char

Definition at line 155 of file string.c.

static size_t potion_utf8char_nextchar ( const char *  s,
size_t  offset 
)
static

returns byte position of next utf8 char after s[offset]

Definition at line 165 of file string.c.

static unsigned long potion_utf8char_decode ( const char *  s)
static

decode the utf8 codepoint at s, i.e. ord

Definition at line 206 of file string.c.

static PN potion_str_slice_index ( PN  index,
size_t  len,
int  nilvalue 
)
inlinestatic

helper function for potion_str_slice to fix index.

Definition at line 220 of file string.c.

PN potion_byte_str ( Potion P,
const char *  str 
)

Definition at line 331 of file string.c.

PN potion_byte_str2 ( Potion P,
const char *  str,
size_t  len 
)

Definition at line 335 of file string.c.

PN potion_bytes ( Potion P,
size_t  len 
)

Definition at line 342 of file string.c.

PN_SIZE pn_printf ( Potion P,
PN  bytes,
const char *  format,
  ... 
)

Definition at line 361 of file string.c.

void potion_bytes_obj_string ( Potion P,
PN  bytes,
PN  obj 
)

Definition at line 384 of file string.c.

void potion_str_hash_init ( Potion P)

Definition at line 487 of file string.c.

void potion_str_init ( Potion P)

Definition at line 491 of file string.c.

Variable Documentation

const uint8_t utf8d[]
static
Initial value:
= {
070,070,070,070,070,070,070,070,070,070,070,070,070,070,070,070,
050,050,050,050,050,050,050,050,050,050,050,050,050,050,050,050,
030,030,030,030,030,030,030,030,030,030,030,030,030,030,030,030,
030,030,030,030,030,030,030,030,030,030,030,030,030,030,030,030,
204,204,188,188,188,188,188,188,188,188,188,188,188,188,188,188,
188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,
174,158,158,158,158,158,158,158,158,158,158,158,158,142,126,126,
111, 95, 95, 95, 79,207,207,207,207,207,207,207,207,207,207,207,
0,1,1,1,8,7,6,4,5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
1,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,8,7,6,4,5,4,3,2,1,1,1,1,
}

Definition at line 188 of file string.c.