18 #define DEFAULT_ANCHOR_FORMAT "id%03d"
23 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
33 char *buff =
S_ALLOC_N(
char, len * 4 / 3 + 6);
37 buff[i++] =
b64_table[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
38 buff[i++] =
b64_table[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
45 buff[i++] =
b64_table[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
46 buff[i++] =
b64_table[077 & (((s[1] << 2) & 074) | ((
'\0' >> 6) & 03))];
51 buff[i++] =
b64_table[077 & (((*s << 4) & 060) | (('\0' >> 4) & 017))];
62 int a = -1,
b = -1,
c = 0,
d;
64 static int b64_xtable[256];
73 for (i = 0; i < 256; i++) {
76 for (i = 0; i < 64; i++) {
81 while (s[0] ==
'\r' || s[0] ==
'\n') { s++; }
82 if ((a = b64_xtable[(
int)s[0]]) == -1)
break;
83 if ((
b = b64_xtable[(
int)s[1]]) == -1)
break;
84 if ((
c = b64_xtable[(
int)s[2]]) == -1)
break;
85 if ((
d = b64_xtable[(
int)s[3]]) == -1)
break;
86 *end++ = a << 2 | b >> 4;
87 *end++ = b << 4 | c >> 2;
91 if (a != -1 &&
b != -1) {
92 if (s + 2 < send && s[2] ==
'=')
93 *end++ = a << 2 | b >> 4;
94 if (
c != -1 && s + 3 < send && s[3] ==
'=') {
95 *end++ = a << 2 | b >> 4;
96 *end++ = b << 4 | c >> 2;
297 if ( len + at >= (
long)e->
bufsize )
302 if (len <= rest)
break;
327 if ( check_room > 0 )
359 char *anchor_name =
NULL;
404 sprintf( an,
"&%s ", anchor_name );
415 sprintf( an,
"*%s", anchor_name );
443 if ( tag ==
NULL )
return;
448 if (
strlen( tag ) == 0 ) {
452 }
else if ( strncmp( tag,
"tag:", 4 ) == 0 ) {
459 const char *subd = tag + 4;
460 while ( *subd !=
':' && *subd !=
'\0' ) subd++;
461 if ( *subd ==
':' ) {
480 }
else if ( strncmp( tag,
"x-private:", 10 ) == 0 ) {
499 spcs[0] =
'\n'; spcs[lvl->
spaces + 1] =
'\0';
500 for ( i = 0; i < lvl->
spaces; i++ ) spcs[i+1] =
' ';
509 #define SCAN_NONPRINT 1
511 #define SCAN_INDENTED 2
515 #define SCAN_WHITEEDGE 8
517 #define SCAN_NEWLINE 16
519 #define SCAN_SINGLEQ 32
521 #define SCAN_DOUBLEQ 64
523 #define SCAN_INDIC_S 128
525 #define SCAN_INDIC_C 256
527 #define SCAN_NONL_E 512
529 #define SCAN_MANYNL_E 1024
531 #define SCAN_FLOWMAP 2048
533 #define SCAN_FLOWSEQ 4096
535 #define SCAN_DOCSEP 8192
546 if ( len < 1 )
return flags;
549 if ( cursor[0] ==
'[' || cursor[0] ==
']' ||
550 cursor[0] ==
'{' || cursor[0] ==
'}' ||
551 cursor[0] ==
'!' || cursor[0] ==
'*' ||
552 cursor[0] ==
'&' || cursor[0] ==
'|' ||
553 cursor[0] ==
'>' || cursor[0] ==
'\'' ||
554 cursor[0] ==
'"' || cursor[0] ==
'#' ||
555 cursor[0] ==
'%' || cursor[0] ==
'@' ||
559 if ( ( cursor[0] ==
'-' || cursor[0] ==
':' ||
560 cursor[0] ==
'?' || cursor[0] ==
',' ) &&
561 ( len == 1 || cursor[1] ==
' ' || cursor[1] ==
'\n' ) )
567 if ( cursor[len-1] !=
'\n' ) {
569 }
else if ( len > 1 && cursor[len-2] ==
'\n' ) {
573 ( len > 0 && ( cursor[0] ==
' ' || cursor[0] ==
'\t' || cursor[0] ==
'\n' || cursor[0] ==
'\r' ) ) ||
574 ( len > 1 && ( cursor[len-1] ==
' ' || cursor[len-1] ==
'\t' ) )
580 if ( len >= 3 && strncmp( cursor,
"---", 3 ) == 0 )
584 for ( i = 0; i <
len; i++ ) {
586 if ( ! ( cursor[i] == 0x9 ||
589 ( cursor[i] >= 0x20 && cursor[i] <= 0x7E ) )
593 else if ( cursor[i] ==
'\n' ) {
595 if ( len - i >= 3 && strncmp( &cursor[i+1],
"---", 3 ) == 0 )
597 if ( cursor[i+1] ==
' ' || cursor[i+1] ==
'\t' )
599 if ( req_width > 0 && i -
start > req_width )
603 else if ( cursor[i] ==
'\'' )
607 else if ( cursor[i] ==
'"' )
611 else if ( cursor[i] ==
']' )
615 else if ( cursor[i] ==
'}' )
620 else if ( ( cursor[i] ==
' ' && cursor[i+1] ==
'#' ) ||
621 ( cursor[i] ==
':' &&
622 ( cursor[i+1] ==
' ' || cursor[i+1] ==
'\n' || i == len - 1 ) ) )
626 else if ( cursor[i] ==
',' &&
627 ( cursor[i+1] ==
' ' || cursor[i+1] ==
'\n' || i == len - 1 ) )
642 char keep_nl,
const char *
str,
long len )
648 const char *match_implicit;
651 if ( str ==
NULL ) str =
"";
702 force_style = favor_style;
710 if ( scan & SCAN_NEWLINE ) {
711 force_style = favor_style;
717 if ( force_indent > 0 ) {
745 switch ( force_style )
779 for( i = 0; i <
len; i++ )
781 if( (src[i] < 0x20) || (0x7E < src[i]) )
813 while ( mark < str + len ) {
823 if ( *start !=
' ' && *start !=
'\n' && *end !=
'\n' && *end !=
' ' ) {
833 if ( width > 0 && *start !=
' ' && mark - end > width ) {
861 while ( mark < str + len ) {
862 if ( do_indent > 0 ) {
863 if ( do_indent == 2 ) {
888 if ( start < str + len && ( *start ==
' ' || *start ==
'\n' ) ) {
894 if ( width > 0 && *start !=
' ' && mark - end > width ) {
923 }
else if ( keep_nl ==
NL_KEEP ) {
927 while ( mark < str + len ) {
928 if ( *mark ==
'\n' ) {
930 if ( *start !=
' ' && *start !=
'\n' && *end !=
'\n' && *end !=
' ' ) end += 1;
932 if ( mark + 1 == str + len ) {
959 }
else if ( keep_nl ==
NL_KEEP ) {
964 while ( mark < str + len ) {
969 if ( *start !=
' ' && *start !=
'\n' && *end !=
'\n' && *end !=
' ' ) {
972 if ( mark + 1 == str + len ) {
981 if ( *start !=
' ' ) {
982 if ( mark - end > width ) {
1065 for ( i = 0; i < spcs; i++ ) {
1095 for ( i = 0; i < spcs; i++ ) {
1102 if ( lvl->
ncount % 2 == 0 ) {
1112 if ( lvl->
ncount % 2 == 0 ) {
1120 spcs[lvl->
spaces] =
'\0';
1121 for ( i = 0; i < lvl->
spaces; i++ ) spcs[i] =
' ';
1133 if ( lvl->
ncount % 2 == 0 ) {
1159 if ( lvl->
ncount == 0 ) {
1171 if ( lvl->
ncount == 0 ) {
1173 }
else if ( lvl->
ncount % 2 == 1 ) {
1196 char *anchor_name =
NULL;
1237 sprintf( anchor_name, anc, idx );
void syck_emitter_st_free(SyckEmitter *e)
enum syck_level_status status
size_t strlen(const char *)
void syck_emitter_flush(SyckEmitter *e, long check_room)
#define S_ALLOC_N(type, n)
SyckEmitter * syck_new_emitter(void)
void syck_emit_tag(SyckEmitter *e, const char *tag, const char *ignore)
void(* SyckOutputHandler)(SyckEmitter *, char *, long)
SYMID syck_emitter_mark_node(SyckEmitter *e, st_data_t n)
void syck_emitter_clear(SyckEmitter *e)
static VALUE mark(VALUE self)
char * syck_base64dec(char *s, long len)
char * syck_strndup(const char *buf, long len)
void syck_emit_scalar(SyckEmitter *e, const char *tag, enum scalar_style force_style, int force_indent, int force_width, char keep_nl, const char *str, long len)
const char * syck_match_implicit(const char *str, size_t len)
void syck_free_emitter(SyckEmitter *e)
void syck_emitter_pop_level(SyckEmitter *e)
void syck_emit_seq(SyckEmitter *e, const char *tag, enum seq_style style)
int syck_tagcmp(const char *tag1, const char *tag2)
void syck_emitter_handler(SyckEmitter *e, SyckEmitterHandler hdlr)
SyckOutputHandler output_handler
#define S_MEMCPY(p1, p2, type, n)
void syck_emitter_reset_levels(SyckEmitter *e)
#define S_REALLOC_N(var, type, n)
int syck_st_free_anchors(char *key, char *name, char *arg)
void syck_emit_end(SyckEmitter *e)
void syck_emit(SyckEmitter *e, st_data_t n)
void syck_emit_indent(SyckEmitter *e)
register unsigned int len
void syck_emit_map(SyckEmitter *e, const char *tag, enum map_style style)
SyckEmitterHandler emitter_handler
void syck_emit_literal(SyckEmitter *e, char keep_nl, const char *str, long len)
void syck_output_handler(SyckEmitter *e, SyckOutputHandler hdlr)
int syck_scan_scalar(int req_width, const char *cursor, long len)
char * syck_taguri(const char *domain, const char *type_id, int type_len)
SyckLevel * syck_emitter_parent_level(SyckEmitter *e)
void syck_emit_item(SyckEmitter *e, st_data_t n)
void syck_emitter_write(SyckEmitter *e, const char *str, long len)
void(* SyckEmitterHandler)(SyckEmitter *, st_data_t)
SyckLevel * syck_emitter_current_level(SyckEmitter *e)
void syck_emit_2quoted(SyckEmitter *e, int width, const char *str, long len)
void syck_emitter_escape(SyckEmitter *e, const char *src, long len)
char * syck_base64enc(char *s, long len)
void syck_emitter_add_level(SyckEmitter *e, int len, enum syck_level_status status)
#define DEFAULT_ANCHOR_FORMAT
void syck_emit_1quoted(SyckEmitter *e, int width, const char *str, long len)
void syck_emit_folded(SyckEmitter *e, int width, char keep_nl, const char *str, long len)
#define S_MEMZERO(p, type, n)