libk  str.h at [b590aba21d]

File kstr/str.h artifact 0c79e2a160 part of check-in b590aba21d


#ifndef KIstr
#define KIstr

#include <k/mem.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct kstr {
	sz size;
	kmptr ptr;
} kstr;

typedef struct ksraw {
	sz size;
	const char* ptr;
} ksraw;

typedef struct ksmut {
	sz size;
	char* ptr;
} ksmut;

#include <k/internal.egroup.h>
typedef enum kscond {
	kscond_ok = kscond_id,
	kscond_fail,
	kscond_unimplemented,
	kscond_nonnumeric,
} kscond;

enum ksconv {
	ksconv_default = 0,

	ksconv_raw = 1,
	ksconv_bin = 2,
	ksconv_oct = 8,
	ksconv_dec = 10,
	ksconv_hex = 16,
	ksconv_b32 = 32,

	ksconv_partial = 1 <<  7,
	ksconv_nopfx   = 1 <<  8,
	ksconv_endh    = 1 <<  9,
	ksconv_endl    = 1 << 10,
};

kscond ks_to_int(ksraw str,
		enum ksconv mode,
		u8* dest, sz size);

kscond ks_of_int(u8* number, sz size,
		enum ksconv mode,
		char* bufstart, sz bufsize);

#ifdef __cplusplus
}
#endif

#endif