Example #1
0
boost::regex IfcUtil::wildcard_string_to_regex(std::string str)
{
    // Escape all non-"*?" regex special chars
    std::string special_chars = "\\^.$|()[]+/";
    foreach(char c, special_chars) {
        std::string char_str(1, c);
        boost::replace_all(str, char_str, "\\"+ char_str);
    }
Example #2
0
int getopt(int argc, char_t *argv[], char_t *optstring)
{
	static char_t *next = NULL;
	if (optind == 0)
		next = NULL;

	optarg = NULL;

	if (next == NULL || *next == char_str('\0'))
	{
		if (optind == 0)
			optind++;

		if (optind >= argc || argv[optind][0] != char_str('-') || argv[optind][1] == char_str('\0'))
		{
			optarg = NULL;
			if (optind < argc)
				optarg = argv[optind];
			return EOF;
		}

        //--S [] 2015/06/05 : Sang-Wook Lee
#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
		//--E [] 2015/06/05 : Sang-Wook Lee
		if (_tcscmp(argv[optind], char_str("--")) == 0)
        //--S [] 2015/06/05 : Sang-Wook Lee
#else
#if defined(_UNICODE) || defined(UNICODE)
		if (wcscmp(argv[optind], char_str("--")) == 0)
#else
		if (strcmp(argv[optind], char_str("--")) == 0)
#endif
#endif
        //--E [] 2015/06/05 : Sang-Wook Lee
		{
			optind++;
			optarg = NULL;
			if (optind < argc)
				optarg = argv[optind];
			return EOF;
		}

		next = argv[optind];
		next++;		// skip past -
		optind++;
	}

	char_t c = *next++;
	//--S [] 2015/06/05 : Sang-Wook Lee
#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
	//--E [] 2015/06/05 : Sang-Wook Lee
	char_t *cp = _tcschr(optstring, c);
	//--S [] 2015/06/05 : Sang-Wook Lee
#else
#if defined(_UNICODE) || defined(UNICODE)
	char_t *cp = wcschr(optstring, c);
#else
	char_t *cp = strchr(optstring, c);
#endif
#endif
	//--E [] 2015/06/05 : Sang-Wook Lee

	if (cp == NULL || c == char_str(':'))
		return char_str('?');

	cp++;
	if (*cp == char_str(':'))
	{
		if (*next != char_str('\0'))
		{
			optarg = next;
			next = NULL;
		}
		else if (optind < argc)
		{
			optarg = argv[optind];
			optind++;
		}
		else
		{
			return char_str('?');
		}
	}

	return c;
}
Example #3
0
static gboolean
unescape_gstring (GString *string)
{
  const gchar *from;
  gchar       *to;

  /*
   * Meeks' theorum: unescaping can only shrink text.
   * for &lt; etc. this is obvious, for &#xffff; more
   * thought is required, but this is patently so.
   */
  for (from = to = string->str; *from != '\0'; from++, to++)
    {
      *to = *from;

      if (*to == '\r')
        {
          *to = '\n';
          if (from[1] == '\n')
            from++;
        }
      if (*from == '&')
        {
          from++;
          if (*from == '#')
            {
              gboolean is_hex = FALSE;
              gulong   l;
              gchar   *end = NULL;

              from++;

              if (*from == 'x')
                {
                  is_hex = TRUE;
                  from++;
                }

              /* digit is between start and p */
              errno = 0;
              if (is_hex)
                l = strtoul (from, &end, 16);
              else
                l = strtoul (from, &end, 10);

              if (end == from || errno != 0)
                {
                  return FALSE;
                }
              else if (*end != ';')
                {
                  return FALSE;
                }
              else
                {
                  /* characters XML 1.1 permits */
                  if ((0 < l && l <= 0xD7FF) ||
                      (0xE000 <= l && l <= 0xFFFD) ||
                      (0x10000 <= l && l <= 0x10FFFF))
                    {
                      gchar buf[8];
                      char_str (l, buf);
                      strcpy (to, buf);
                      to += strlen (buf) - 1;
                      from = end;
                    }
                  else
                    {
                      return FALSE;
                    }
                }
            }

          else if (strncmp (from, "lt;", 3) == 0)
            {
              *to = '<';
              from += 2;
            }
          else if (strncmp (from, "gt;", 3) == 0)
            {
              *to = '>';
              from += 2;
            }
          else if (strncmp (from, "amp;", 4) == 0)
            {
              *to = '&';
              from += 3;
            }
          else if (strncmp (from, "quot;", 5) == 0)
            {
              *to = '"';
              from += 4;
            }
          else if (strncmp (from, "apos;", 5) == 0)
            {
              *to = '\'';
              from += 4;
            }
          else
            {
              return FALSE;
            }
        }
    }

  g_assert (to - string->str <= string->len);
  if (to - string->str != string->len)
    g_string_truncate (string, to - string->str);

  return TRUE;
}