示例#1
0
	void ViewCompilerImpl::codegen_constructor_set_style(const std::string &name, const ViewClassMembers &members)
	{
		if (!members.style.empty())
			add_line("\t\t%1style()->set(\"%2\");", name, string_escape(members.style));

		for (const auto &child : members.children)
		{
			codegen_constructor_set_style(child.id + "->", child);
		}
	}
示例#2
0
文件: node.c 项目: 0x00evil/streem
node*
node_string_new(const char* s, size_t len)
{
  node* np = malloc(sizeof(node));

  np->type = NODE_VALUE;
  np->value.t = NODE_VALUE_STRING;
  len = string_escape((char*)s, len);
  np->value.v.s = strm_str_new(s, len);
  return np;
}
示例#3
0
/** Formats the list of command line arguments in <b>args</b> as a string.
 * Arguments that contain ' ', '\', or '"' tokens will be escaped and
 * wrapped in double quotes. */
QString
string_format_arguments(const QStringList &args)
{
  QStringList out;
  foreach (QString arg, args) {
    if (arg.contains("\"") || arg.contains("\\") || arg.contains(" "))
      out << string_escape(arg);
    else 
      out << arg;
  }
  return out.join(" ");
}
示例#4
0
文件: output.c 项目: 3van/libason
/**
 * Print an ASON value as a string.
 **/
static char *
ason_do_asprint(ason_t *value, int use_unicode)
{
	char *tmp;
	char *ret;

	switch (value->type) {
	case ASON_TYPE_NUMERIC:
		return ason_asprint_number(value->n);
	case ASON_TYPE_EMPTY:
		if (use_unicode)
			return xasprintf("∅");
		else
			return xasprintf("_");
	case ASON_TYPE_NULL:
		return xasprintf("null");
	case ASON_TYPE_TRUE:
		return xasprintf("true");
	case ASON_TYPE_FALSE:
		return xasprintf("false");
	case ASON_TYPE_STRING:
		tmp = string_escape(value->string);
		ret = xasprintf("\"%s\"", tmp);
		free(tmp);
		return ret;
	case ASON_TYPE_UNIVERSE:
		return xasprintf("U");
	case ASON_TYPE_WILD:
		return xasprintf("*");
	case ASON_TYPE_INTERSECT:
	case ASON_TYPE_JOIN:
	case ASON_TYPE_REPR:
	case ASON_TYPE_EQUAL:
		return ason_asprint_operator(value, use_unicode);
	case ASON_TYPE_UNION:
		return ason_asprint_union(value, use_unicode);
	case ASON_TYPE_OBJECT:
	case ASON_TYPE_UOBJECT:
		return ason_asprint_object(value, use_unicode);
	case ASON_TYPE_LIST:
		return ason_asprint_list(value, use_unicode);
	case ASON_TYPE_COMP:
		tmp = ason_do_asprint(value->items[0], use_unicode);
		if (ason_get_precedence(value->items[0]->type) < INT_MAX)
			ret = xasprintf("!( %s )", tmp);
		else
			ret = xasprintf("!%s", tmp);
		free(tmp);
		return ret;
	default:
		errx(1, "Unreachable statement at %s:%d", __FILE__, __LINE__);
	};
}
示例#5
0
	void ViewCompilerImpl::codegen_constructor_set_value(const std::string &name, const ViewClassMembers &members)
	{
		if (!members.values.empty())
		{
			add_line("\t\t%1set_properties(", name);
			add_line("\t\t{");
			bool first = true;
			for (const auto &it : members.values)
			{
				if (first)
					add_line("\t\t\t{ \"%1\", \"%2\" }", string_escape(it.first), string_escape(it.second));
				else
					add_line("\t\t\t,{ \"%1\", \"%2\" }", string_escape(it.first), string_escape(it.second));
				first = false;
			}
			add_line("\t\t});");
		}

		for (const auto &child : members.children)
		{
			codegen_constructor_set_value(child.id + "->", child);
		}
	}
示例#6
0
文件: turtle.c 项目: brayc0/nlfetdb
static foreign_t
turtle_read_relative_uri(term_t C0, term_t Stream, term_t C, term_t Value)
{ int c;
  charbuf b;
  IOSTREAM *in;

  if ( !PL_get_integer(C0, &c) )
    return type_error(C0, "code");
  if ( c != '<' )
    return FALSE;

  if ( !PL_get_stream_handle(Stream, &in) )
    return FALSE;

  init_charbuf(&b);
  c = Sgetcode(in);
  for(; ; c = Sgetcode(in))
  { if ( c == '>' )
    { int rc;

      c = Sgetcode(in);
      rc = (PL_unify_integer(C, c) &&
	    PL_unify_wchars(Value, PL_ATOM, b.here-b.base, b.base));
      PL_release_stream(in);
      free_charbuf(&b);
      return rc;
    } else if ( c == '\\' )
    { int esc;

      c = Sgetcode(in);
      if ( c == '>' )
      { add_charbuf(&b, c);
      } else if ( string_escape(in, c, &esc) )
      { add_charbuf(&b, esc);
      } else
      { free_charbuf(&b);
	PL_release_stream(in);
	return FALSE;
      }
    } else if ( c == -1 )
    { free_charbuf(&b);
      PL_release_stream(in);
      return syntax_error("eof_in_uri", in);
    } else
    { add_charbuf(&b, c);
    }
  }
}
示例#7
0
文件: decomment.c 项目: chrisnc/knrc
int main(void)
{
  int c;
  int state = NO_COMMENT;
  while ((c = getchar()) != EOF)
  {
    switch (state)
    {
    case NO_COMMENT:
      state = no_comment(c);
      break;
    case OPENING_SLASH:
      state = opening_slash(c);
      break;
    case C_COMMENT:
      state = c_comment(c);
      break;
    case CLOSING_STAR:
      state = closing_star(c);
      break;
    case LINE_COMMENT:
      state = line_comment(c);
      break;
    case IN_STRING:
      state = in_string(c);
      break;
    case IN_CHAR_LIT:
      state = in_char_lit(c);
      break;
    case STRING_ESCAPE:
      state = string_escape(c);
      break;
    case CHAR_LIT_ESCAPE:
      state = char_lit_escape(c);
      break;
    default:
      printf("error, unknown state: %d\n", state);
      return 1;
    }
  }
}
示例#8
0
文件: output.c 项目: 3van/libason
/**
 * Print an ASON object as a string.
 **/
static char *
ason_asprint_object(ason_t *value, int use_unicode)
{
	char *out = NULL;
	char *tmp;
	char *next;
	char *key;
	size_t i;

	/* FIXME: Escaping for keys. */
	for (i = 0; i < value->count; i++) {
		next = ason_do_asprint(value->kvs[i].value, use_unicode);

		tmp = next;
		key = string_escape(value->kvs[i].key);
		next = xasprintf("\"%s\": %s", key, next);
		free(tmp);
		free(key);

		if (out) {
			tmp = out;
			out = xasprintf("%s, %s", out, next);
			free(tmp);
			free(next);
		} else {
			out = next;
		}
	}

	if (out && value->type == ASON_TYPE_UOBJECT)
		tmp = xasprintf("{ %s, *}", out);
	else if (out)
		tmp = xasprintf("{ %s }", out);
	else if (value->type == ASON_TYPE_UOBJECT)
		tmp = xasprintf("{*}");
	else
		tmp = xasprintf("{}");
	free(out);
	return tmp;
}
示例#9
0
文件: config.c 项目: XQF/xqf
void config_set_string (const char *path, const char *str) {
	config_set_raw (path, string_escape (str));
}
示例#10
0
int code_dump2(code_t*c, abc_exception_list_t*exceptions, abc_file_t*file, char*prefix, FILE*fo)
{
    abc_exception_list_t*e = exceptions;
    c = code_start(c);
    currentstats_t*stats =  code_get_stats(c, exceptions);

    int pos = 0;
    while(c) {
	U8 opcode = c->opcode;
	char found = 0;
        opcode_t*op = opcode_get(opcode);

        e = exceptions;
        while(e) {
            if(c==e->abc_exception->from)
                fprintf(fo, "%s   TRY {\n", prefix);
            if(c==e->abc_exception->target) {
                char*s1 = multiname_tostring(e->abc_exception->exc_type);
                char*s2 = multiname_tostring(e->abc_exception->var_name);
                fprintf(fo, "%s   CATCH(%s %s)\n", prefix, s1, s2);
                free(s1);
                free(s2);
            }
            e = e->next;
        }

	if(!op) {
	    fprintf(stderr, "Can't parse opcode %02x.\n", opcode);
	    return 0;
	} else {
            char*p = op->params;
            char first = 1;
            int i=0;

            if(stats) {
                int f = stats->stack[c->pos].flags;
                fprintf(fo, "%s%05d) %c %d:%d %s ", prefix, c->pos, 
                                       (f&FLAG_ERROR)?'E':((f&FLAG_SEEN)?'+':'|'),
                                       stats->stack[c->pos].stackpos,
                                       stats->stack[c->pos].scopepos,
                                       op->name);
            } else {
                fprintf(fo, "%s%05d) ? ?:? %s ", prefix, c->pos, op->name);
            }

            while(*p) {
                void*data = c->data[i];
                if(i>0)
                    printf(", ");

                if(*p == 'n') {
                    int n = (ptroff_t)data;
                    fprintf(fo, "%d params", n);
                } else if(*p == '2') {
                    multiname_t*n = (multiname_t*)data;
                    char* m = multiname_tostring(n);
                    fprintf(fo, "%s", m);
                    free(m);
                } else if(*p == 'N') {
                    namespace_t*ns = (namespace_t*)data;
                    char* m = namespace_tostring(ns);
                    fprintf(fo, "%s", m);
                    free(m);
                } else if(*p == 'm') {
                    abc_method_t*m = (abc_method_t*)data;
                    fprintf(fo, "[method %08x %s]", m->index, m->name);
                } else if(*p == 'c') {
                    abc_class_t*cls = (abc_class_t*)data;
                    char*classname = multiname_tostring(cls->classname);
                    fprintf(fo, "[classinfo %08x %s]", cls->index, classname);
                    free(classname);
                } else if(*p == 'i') {
                    abc_method_body_t*b = (abc_method_body_t*)data;
                    fprintf(fo, "[methodbody]");
                } else if(*p == 'u' || *p == 'I' || *p == 'U') {
                    int n = (ptroff_t)data;
                    fprintf(fo, "%d", n);
                } else if(*p == 'f') {
                    double f = *(double*)data;
                    fprintf(fo, "%f", f);
                } else if(*p == 'r') {
                    int n = (ptroff_t)data;
                    fprintf(fo, "r%d", n);
                } else if(*p == 'b') {
                    int b = (signed char)(ptroff_t)data;
                    fprintf(fo, "%d", b);
                } else if(*p == 'j') {
                    if(c->branch)
                        fprintf(fo, "->%d", c->branch->pos);
                    else
                        fprintf(fo, "%08x", (unsigned int)c->branch);
                } else if(*p == 's') {
                    char*s = string_escape((string_t*)data);
                    fprintf(fo, "\"%s\"", s);
                    free(s);
                } else if(*p == 'D') {
                    fprintf(fo, "[register %02x=%s]", (ptroff_t)c->data[1], (char*)c->data[0]);
                } else if(*p == 'S') {
                    lookupswitch_t*l = c->data[0];
                    fprintf(fo, "[");
                    if(l->def)
                        fprintf(fo, "default->%d", l->def->pos);
                    else
                        fprintf(fo, "default->00000000");
                    code_list_t*t = l->targets;
                    while(t) {
                        if(t->code)
                            fprintf(fo, ",->%d", t->code->pos);
                        else
                            fprintf(fo, ",->00000000");
                        t = t->next;
                    }
                    fprintf(fo, "]");
                } else {
                    fprintf(stderr, "Can't parse opcode param type \"%c\"\n", *p);
                    return 0;
                }
                p++;
                i++;
                first = 0;
            }
            fprintf(fo, "\n");
	}
        
        e = exceptions;
        while(e) {
            if(c==e->abc_exception->to) {
                if(e->abc_exception->target)
                    fprintf(fo, "%s   } // END TRY (HANDLER: %d)\n", prefix, e->abc_exception->target->pos);
                else
                    fprintf(fo, "%s   } // END TRY (HANDLER: 00000000)\n", prefix);
            }
            e = e->next;
        }

        pos++;
        c = c->next;
    }
    stats_free(stats);
    return 1;
}
示例#11
0
文件: turtle.c 项目: brayc0/nlfetdb
static foreign_t
turtle_read_string(term_t C0, term_t Stream, term_t C, term_t Value)
{ int c;
  charbuf b;
  IOSTREAM *in;
  int endlen = 1;

  if ( !PL_get_integer(C0, &c) )
    return type_error(C0, "code");
  if ( c != '"' )
    return FALSE;

  if ( !PL_get_stream_handle(Stream, &in) )
    return FALSE;

  init_charbuf(&b);

  c = Sgetcode(in);
  if ( c == '"' )
  { c = Sgetcode(in);
    if ( c == '"' )			/* """...""" */
    { endlen = 3;
      c = Sgetcode(in);
    } else
    { PL_release_stream(in);
      return (PL_unify_integer(C, c) &&
	      PL_unify_atom(Value, ATOM_));
    }
  }

  for(;;c = Sgetcode(in))
  { if ( c == -1 )
    { free_charbuf(&b);
      PL_release_stream(in);
      return syntax_error("eof_in_string", in);
    } else if ( c == '"' )
    { int count = 1;

      for(count=1; count<endlen; )
      { if ( (c=Sgetcode(in)) == '"' )
	  count++;
	else
	  break;
      }

      if ( count == endlen )
      { int rc;

	c = Sgetcode(in);
	rc = (PL_unify_integer(C, c) &&
	      PL_unify_wchars(Value, PL_ATOM, b.here-b.base, b.base));
	free_charbuf(&b);
	PL_release_stream(in);
	return rc;
      }

      while(count-- > 0)
	add_charbuf(&b, '"');
      add_charbuf(&b, c);
    } else if ( c == '\\' )
    { int esc;

      c = Sgetcode(in);
      if ( !string_escape(in, c, &esc) )
      { free_charbuf(&b);
	PL_release_stream(in);
	return FALSE;
      }
      add_charbuf(&b, esc);
    } else
    { add_charbuf(&b, c);
    }
  }
}
示例#12
0
文件: node.c 项目: 0x00evil/streem
strm_string*
node_id_escaped(const char* s, size_t len)
{
  len = string_escape((char*)s, len);
  return strm_str_intern(s, len);
}