Пример #1
0
Файл: cli.c Проект: mhfan/stoken
static void print_formatted(const char *buf)
{
	char *formatted;

	formatted = format_token(buf);
	puts(formatted);
	free(formatted);
}
Пример #2
0
int main(int argc, char **argv) {
  uuid_state state;
  uuid_t uuid;
  char output[1024];

  create_uuid_state(&state);
  create_token(&state, &uuid);
  format_token(output, &uuid);

  printf("%s\n", output);
  
}
Пример #3
0
int tfs_excel_generate(char *format, tfs_token_array_t *token_array) {
    int i;
    char *out = format;
    const char *display_chars = "$-+/():!^&'~{}<>= ";
    int is_quoting = 0;
    int error = 0;
    int previous_time_unit = 0;
    for (i=0; i<token_array->count; i++) {
        tfs_token_t *token = &token_array->tokens[i];
        if (token->is_literal) {
            char *in = token->text;
            while (*in) {
                if (is_quoting) {
                    if (*in == '"') {
                        *out++ = '\\';
                    } else if (strchr(display_chars, *in) != NULL) {
                        *out++ = '"';
                        is_quoting = 0;
                    }
                    *out++ = *in;
                } else {
                    if (strchr(display_chars, *in) == NULL) {
                        *out++ = '"';
                        if (*in == '"') {
                            *out++ = '\\';
                        }
                        is_quoting = 1;
                    }
                    *out++ = *in;
                }
                in++;
            }
        } else if (token->time_unit) {
            if (is_quoting) {
                *out++ = '"';
                is_quoting = 0;
            }
            out = format_token(out, token);
            if (out == NULL) {
                error = TFS_CANT_REPRESENT;
                break;
            }
            previous_time_unit = token->time_unit;
        }
    }
    if (is_quoting) {
        *out++ = '"';
    }
    return error;
}
Пример #4
0
tfs_error_e tfs_posix_generate(char *format, size_t format_len, tfs_token_array_t *token_array) {
    int i;
    tfs_error_e error = TFS_OK;
    char *out = format;
    char *last = format + format_len;
    for (i=0; i<token_array->count; i++) {
        tfs_token_t *token = &token_array->tokens[i];
        if (token->is_literal) {
            char *in = token->text;
            while (*in && out < last) {
                if (*in == '%' || *in == '\n' || *in == '\t') {
                    *out++ = '%';
                    if (out < last) {
                        if (*in == '\n') {
                            *out++ = 'n';
                        } else if (*in == '\t') {
                            *out++ = 't';
                        } else {
                            *out++ = *in;
                        }
                    }
                } else {
                    *out++ = *in;
                }
                in++;
            }
        } else if (token->time_unit) {
            out = format_token(out, last - out, token);
            if (out == NULL) {
                error = TFS_CANT_REPRESENT;
                break;
            }
        }
        if (out == last)
            break;
    }
    if (out < last)
        *out++ = '\0';
    return error;
}
Пример #5
0
 String UUID::toString() const
 {
    char buffer[ 1024 ];
    format_token( buffer, ( xuuid_t* ) this );
    return buffer;
 }