当前位置: 首页>>代码示例>>C++>>正文


C++ quote_string函数代码示例

本文整理汇总了C++中quote_string函数的典型用法代码示例。如果您正苦于以下问题:C++ quote_string函数的具体用法?C++ quote_string怎么用?C++ quote_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了quote_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: enter_record

static void
enter_record(
    char *	name,
    int		level,
    time_t	dumpdate)
{
    amandates_t *amdp;
    char *qname;

    amdp = lookup(name, 0);

    if (level < 0 || level >= DUMP_LEVELS) {
	qname = quote_string(name);
	/* this is not allowed, but we can ignore it */
        dbprintf(_("amandates botch: %s lev %d: new dumpdate %ld\n"),
		  qname, level, (long) dumpdate);
	amfree(qname);
	return;
    } else if(dumpdate < amdp->dates[level]) {
	qname = quote_string(name);
	/* this is not allowed, but we can ignore it */
        dbprintf(_("amandates botch: %s lev %d: new dumpdate %ld old %ld\n"),
		  qname, level, (long) dumpdate, (long) amdp->dates[level]);
	amfree(qname);
	return;
    }

    amdp->dates[level] = dumpdate;
}
开发者ID:neepher,项目名称:amanda,代码行数:29,代码来源:amandates.c

示例2: test_strquotedstr_skipping

/****
 * Test the strquotedstr function
 */
static int
test_strquotedstr_skipping(void)
{
    char **iter1, **iter2;
    gboolean success = TRUE;

    /* the idea here is to loop over all pairs of strings, forming a
     * string by quoting them with quote_string and inserting a space, then
     * re-splitting with strquotedstr.  This should get us back to our
     * starting point. Note that we have to begin with a non-quoted identifier,
     * becuse strquotedstr requires that strtok_r has already been called. */

    for (iter1 = quotable_strings; *iter1; iter1++) {
	for (iter2 = quotable_strings; *iter2; iter2++) {
	    char *q1 = quote_string(*iter1);
	    char *q2 = quote_string(*iter2);
	    char *combined = vstralloc("START ", q1, " ", q2, NULL);
	    char *copy = g_strdup(combined);
	    char *saveptr = NULL;
	    char *tok;
	    int i;

	    tok = strtok_r(copy, " ", &saveptr);

	    for (i = 1; i <= 2; i++) {
		char *expected = (i == 1)? q1:q2;
		tok = strquotedstr(&saveptr);
		if (!tok) {
		    g_fprintf(stderr, "while parsing '%s', call %d to strquotedstr returned NULL\n",
			      combined, i);
		    success = FALSE;
		    goto next;
		}
		if (0 != strcmp(tok, expected)) {
		    char *safe = safestr(tok);

		    g_fprintf(stderr, "while parsing '%s', call %d to strquotedstr returned '%s' "
			      "but '%s' was expected.\n",
			      combined, i, safe, expected);
		    success = FALSE;
		    goto next;
		}
	    }

	    if (strquotedstr(&saveptr) != NULL) {
		g_fprintf(stderr, "while parsing '%s', call 3 to strquotedstr did not return NULL\n",
			  combined);
		success = FALSE;
		goto next;
	    }
next:
	    amfree(q1);
	    amfree(q2);
	    amfree(copy);
	    amfree(combined);
	}
    }

    return success;
}
开发者ID:malclocke,项目名称:amanda,代码行数:63,代码来源:quoting-test.c

示例3: amandates_updateone

void
amandates_updateone(
    char *	name,
    int		level,
    time_t	dumpdate)
{
    amandates_t *amdp;
    char *qname;

    assert(!readonly);

    amdp = lookup(name, 1);

    if (level < 0 || level >= DUMP_LEVELS) {
	/* this is not allowed, but we can ignore it */
	qname = quote_string(name);
	dbprintf(_("amandates updateone: %s lev %d: bad level, dumpdate %ld"),
		  name, level, (long) dumpdate);
	amfree(qname);
	return;
    } else if (dumpdate < amdp->dates[level]) {
	/* this is not allowed, but we can ignore it */
	qname = quote_string(name);
	dbprintf(_("amandates updateone: %s lev %d: new dumpdate %ld old %ld"),
		  name, level, (long) dumpdate, (long) amdp->dates[level]);
	amfree(qname);
	return;
    }

    amdp->dates[level] = dumpdate;
    updated = 1;
}
开发者ID:neepher,项目名称:amanda,代码行数:32,代码来源:amandates.c

示例4: print_id

/* Print a user ID, with a default string (like "everyone") for NULL. */
static void print_id(struct gale_text var,struct gale_text dfl) {
	struct gale_text value = gale_var(var);
	int i = 1;

	if (0 == value.l) {
		gale_print(stdout,0,G_(" *"));
		gale_print(stdout,gale_print_bold,dfl);
		gale_print(stdout,0,G_("*"));
		return;
	}

	do {
                int at;
		struct gale_text local,domain;
		gale_print(stdout,0,G_(" "));
                for (at = 0; at < value.l && '@' != value.p[at]; ++at) ;
		local = gale_text_left(value,at);
		domain = gale_text_right(value,-at);
		if (quote_string(&local) || quote_string(&domain)) {
			gale_print(stdout,0,G_("'"));
			gale_print(stdout,gale_print_bold,local);
			gale_print(stdout,0,domain);
			gale_print(stdout,0,G_("'"));
		} else {
			gale_print(stdout,gale_print_bold,local);
			gale_print(stdout,0,domain);
		}

		value = gale_var(gale_text_concat(3,var,G_("_"),
			gale_text_from_number(++i,10,0)));
	} while (0 != value.l);
}
开发者ID:grawity,项目名称:gale,代码行数:33,代码来源:default.c

示例5: first

/* We call this when we can't find a tape to write data to. This could
   happen with the first (or only) part of a file, but it could also
   happen with an intermediate part of a split dump. dump_bytes
   is 0 if this is the first part of a dump. */
static void bail_no_volume(
    dump_info_t *dump_info,
    char *errmsg)
{
    char *errstr;
    if (errmsg)
	errstr = quote_string(errmsg);
    else
	errstr = quote_string("no new tape");
    if (dump_info->total_bytes > 0) {
        /* Second or later part of a split dump, so PARTIAL message. */
        double dump_time = g_timeval_to_double(dump_info->total_time);
        guint64 dump_kbytes = dump_info->total_bytes / 1024;
        double dump_kbps = get_kbps(dump_kbytes, dump_time);
        putresult(PARTIAL,
                  "%s INPUT-GOOD TAPE-ERROR "
                  "\"[sec %f kb %ju kps %f]\" \"\" %s\n",
                  dump_info->handle, 
                  dump_time, (uintmax_t)dump_kbytes, dump_kbps, errstr);
        put_partial_log(dump_info, dump_time, dump_kbytes, errstr);
    } else {
        char * qdiskname = quote_string(dump_info->diskname);
        putresult(FAILED,
                  "%s INPUT-GOOD TAPE-ERROR \"\" %s\n",
                  dump_info->handle, errstr);
        log_add(L_FAIL, "%s %s %s %d %s",
                dump_info->hostname, qdiskname, dump_info->timestamp,
                dump_info->level, errstr);
	amfree(qdiskname);
    }
    amfree(errstr);
}
开发者ID:regina,项目名称:amanda,代码行数:36,代码来源:taper.c

示例6: unparse_name_fixed

static krb5_error_code
unparse_name_fixed(krb5_context context,
		   krb5_const_principal principal,
		   char *name,
		   size_t len,
		   int flags)
{
    size_t idx = 0;
    int i;
    int short_form = (flags & KRB5_PRINCIPAL_UNPARSE_SHORT) != 0;
    int no_realm = (flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) != 0;
    int display = (flags & KRB5_PRINCIPAL_UNPARSE_DISPLAY) != 0;

    if (!no_realm && princ_realm(principal) == NULL) {
	krb5_set_error_message(context, ERANGE,
			       N_("Realm missing from principal, "
				  "can't unparse", ""));
	return ERANGE;
    }

    for(i = 0; i < princ_num_comp(principal); i++){
	if(i)
	    add_char(name, idx, len, '/');
	idx = quote_string(princ_ncomp(principal, i), name, idx, len, display);
	if(idx == len) {
	    krb5_set_error_message(context, ERANGE,
				   N_("Out of space printing principal", ""));
	    return ERANGE;
	}
    }
    /* add realm if different from default realm */
    if(short_form && !no_realm) {
	krb5_realm r;
	krb5_error_code ret;
	ret = krb5_get_default_realm(context, &r);
	if(ret)
	    return ret;
	if(strcmp(princ_realm(principal), r) != 0)
	    short_form = 0;
	free(r);
    }
    if(!short_form && !no_realm) {
	add_char(name, idx, len, '@');
	idx = quote_string(princ_realm(principal), name, idx, len, display);
	if(idx == len) {
	    krb5_set_error_message(context, ERANGE,
				   N_("Out of space printing "
				      "realm of principal", ""));
	    return ERANGE;
	}
    }
    return 0;
}
开发者ID:crherar,项目名称:Admin,代码行数:53,代码来源:principal.c

示例7: check_space

static void
check_space(
    char *	dir,
    off_t	kbytes)
{
    struct fs_usage fsusage;
    char *quoted = quote_string(dir);
    intmax_t kb_avail;

    if(get_fs_usage(dir, NULL, &fsusage) == -1) {
	g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
	amfree(quoted);
	return;
    }

    /* do the division first to avoid potential integer overflow */
    kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;

    if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
	g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
		(long long)kbytes);
    } else if (kb_avail < kbytes) {
	g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
		(long long)kbytes,
		(long long)kb_avail);
    } else {
	g_printf(_("OK %s has more than %lldKB available.\n"),
		quoted, (long long)kbytes);
    }
    amfree(quoted);
}
开发者ID:B-Rich,项目名称:amanda,代码行数:31,代码来源:selfcheck.c

示例8: amgtar_selfcheck

static void
amgtar_selfcheck(
    application_argument_t *argument)
{
    amgtar_build_exinclude(&argument->dle, 1, NULL, NULL, NULL, NULL);

    printf("OK amgtar\n");
    if (gnutar_path) {
	check_file(gnutar_path, X_OK);
    } else {
	printf(_("ERROR [GNUTAR program not available]\n"));
    }

    set_root_privs(1);
    if (gnutar_listdir && strlen(gnutar_listdir) == 0)
	gnutar_listdir = NULL;
    if (gnutar_listdir) {
	check_dir(gnutar_listdir, R_OK|W_OK);
    } else {
	printf(_("ERROR [No GNUTAR-LISTDIR]\n"));
    }

    if (argument->dle.disk) {
	char *qdisk = quote_string(argument->dle.disk);
	fprintf(stdout, "OK %s\n", qdisk);
	amfree(qdisk);
    }
    if (gnutar_directory) {
	check_dir(gnutar_directory, R_OK);
    } else if (argument->dle.device) {
	check_dir(argument->dle.device, R_OK);
    }
    set_root_privs(0);
}
开发者ID:duckhead,项目名称:amanda,代码行数:34,代码来源:amgtar.c

示例9: g_return_val_if_fail

GncSqlStatementPtr
GncSqlBackend::build_update_statement(const gchar* table_name,
                                      QofIdTypeConst obj_name, gpointer pObject,
                                      const EntryVec& table) const noexcept
{
    GncSqlStatementPtr stmt;
    std::ostringstream sql;

    g_return_val_if_fail (table_name != nullptr, nullptr);
    g_return_val_if_fail (obj_name != nullptr, nullptr);
    g_return_val_if_fail (pObject != nullptr, nullptr);


    PairVec values{get_object_values (obj_name, pObject, table)};

    // Create the SQL statement
    sql <<  "UPDATE " << table_name << " SET ";

    for (auto const& col_value : values)
    {
        if (col_value != *values.begin())
            sql << ",";
        sql << col_value.first << "=" <<
            quote_string(col_value.second);
    }

    stmt = create_statement_from_sql(sql.str());
    /* We want our where condition to be just the first column and
     * value, i.e. the guid of the object.
     */
    values.erase(values.begin() + 1, values.end());
    stmt->add_where_cond(obj_name, values);
    return stmt;
}
开发者ID:codesmythe,项目名称:gnucash,代码行数:34,代码来源:gnc-sql-backend.cpp

示例10: process_driver_command

/* In running mode (not startup mode), get a command from driver and
   deal with it. */
static gboolean process_driver_command(taper_state_t * state) {
    struct cmdargs *cmdargs;
    char * q;

    /* This will return QUIT if driver has died. */
    cmdargs = getcmd();
    switch (cmdargs->cmd) {
    case PORT_WRITE:
        /*
         * PORT-WRITE
         *   handle
         *   hostname
         *   features
         *   diskname
         *   level
         *   datestamp
         *   splitsize
         *   split_diskbuffer
         */
        process_port_write(state, cmdargs);
        break;
        
    case FILE_WRITE:
        /*
         * FILE-WRITE
         *   handle
         *   filename
         *   hostname
         *   features
         *   diskname
         *   level
         *   datestamp
         *   splitsize
         */
        process_file_write(state, cmdargs);
        break;
        
    case QUIT:
	free_cmdargs(cmdargs);
	if (state->device && state->device->volume_label) {
	    log_add(L_INFO, "tape %s kb %lld fm %d [OK]\n",
		    state->device->volume_label,
		    (long long)((state->total_bytes+(off_t)1023) / (off_t)1024),
		    state->device->file);
	}
        return send_quitting(state);
    default:
        if (cmdargs->argc >= 1) {
            q = quote_string(cmdargs->argv[0]);
        } else {
            q = stralloc("(no input?)");
        }
        putresult(BAD_COMMAND, "%s\n", q);
        amfree(q);
        break;
    }
    free_cmdargs(cmdargs);

    return TRUE;
}
开发者ID:regina,项目名称:amanda,代码行数:62,代码来源:taper.c

示例11: test_round_trip

static int
test_round_trip(void)
{
    char **strp;
    gboolean success = TRUE;

    for (strp = quotable_strings; *strp; strp++) {
	char *quoted, *unquoted;

	quoted = quote_string(*strp);
	unquoted = unquote_string(quoted);

	/* if they're not the same, complain */
	if (0 != strcmp(*strp, unquoted)) {
	    char *safe_orig = safestr(*strp);
	    char *safe_quoted = safestr(quoted);
	    char *safe_unquoted = safestr(unquoted);

	    printf("  bad round-trip: %s -quote_string-> %s -unquote_string-> %s\n",
		safe_orig, safe_quoted, safe_unquoted);

	    amfree(safe_orig);
	    amfree(safe_quoted);
	    amfree(safe_unquoted);

	    success = FALSE;
	}

	amfree(quoted);
	amfree(unquoted);
    }

    return success;
}
开发者ID:malclocke,项目名称:amanda,代码行数:34,代码来源:quoting-test.c

示例12: test_split_quoted_strings

static int
test_split_quoted_strings(void)
{
    char **iter1, **iter2, **iter3;
    gboolean success = TRUE;
    char *middle_strings[] = {
	"",
	"foo",
	"\"foo\"",
	"sp aces",
	NULL,
    };

    /* the idea here is to loop over all triples of strings, forming a
     * string by quoting them with quote_string and inserting a space, then
     * re-splitting with split_quoted_string.  This should get us back to our
     * starting point. */

    for (iter1 = quotable_strings; *iter1; iter1++) {
	for (iter2 = middle_strings; *iter2; iter2++) {
	    for (iter3 = quotable_strings; *iter3; iter3++) {
		char *q1 = quote_string(*iter1);
		char *q2 = quote_string(*iter2);
		char *q3 = quote_string(*iter3);
		const char *expected[4] = { *iter1, *iter2, *iter3, NULL };
		char *combined = vstralloc(q1, " ", q2, " ", q3, NULL);
		char **tokens;

		tokens = split_quoted_strings(combined);

		success = compare_strv(expected, tokens, "split_quoted_strings", combined)
			&& success;

		amfree(q1);
		amfree(q2);
		amfree(q3);
		amfree(combined);
		g_strfreev(tokens);
	    }
	}
    }

    return success;
}
开发者ID:malclocke,项目名称:amanda,代码行数:44,代码来源:quoting-test.c

示例13: quote_string_test

static void
quote_string_test(void)
{
    char const source[] = "foobar";
    char buffer[12];
    char *buffer_end = buffer + sizeof buffer;
    
    int result = quote_string(source, "<%=", "%>", buffer, buffer_end);
    assert(0 == result);
    ASSERT_STR_EQ("<%=foobar%>", buffer);
}
开发者ID:donmccaughey,项目名称:chars,代码行数:11,代码来源:quote_tests.c

示例14: put_partial_log

/* Put an L_PARTIAL message to the logfile. */
static void put_partial_log(dump_info_t * dump_info, double dump_time,
                            guint64 dump_kbytes, char *errstr) {
    char * qdiskname = quote_string(dump_info->diskname);

    log_add(L_PARTIAL, "%s %s %s %d %d [sec %f kb %ju kps %f] %s",
            dump_info->hostname, qdiskname, dump_info->timestamp,
            dump_info->current_part, dump_info->level, dump_time,
            (uintmax_t)dump_kbytes, get_kbps(dump_kbytes, dump_time),
	    errstr);
    amfree(qdiskname);
}
开发者ID:regina,项目名称:amanda,代码行数:12,代码来源:taper.c

示例15: quote_string_for_empty_quotes_test

static void
quote_string_for_empty_quotes_test(void)
{
    char const source[] = "foobar";
    char buffer[7];
    char *buffer_end = buffer + sizeof buffer;
    
    int result = quote_string(source, "", "", buffer, buffer_end);
    
    assert(0 == result);
    ASSERT_STR_EQ("foobar", buffer);
}
开发者ID:donmccaughey,项目名称:chars,代码行数:12,代码来源:quote_tests.c


注:本文中的quote_string函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。