Exemplo n.º 1
0
FILE* fopen( const std::string& filename, const char* mode )
{
  if ( contains_non_ascii( filename ) )
  {
    assert( false && "File Names with non-ascii characters cannot be opened when built with MinGW." );
    return nullptr;
  }
  return ::fopen( filename.c_str(), mode );
}
Exemplo n.º 2
0
void ifstream::open( const char* name, openmode mode )
{
#ifdef _MSC_VER
  // This is intentionally "_MSC_VER" instead of "SC_WINDOWS".
  // MS's c++ std library provides
  //   std::fstream::open( const wchar_t*, openmode )
  // as an extension to open files with Unicode names.
  // The MinGW c++ std library does not. Since neither
  // library will accept UTF-8 encoded names, there is
  // no way to open a file with a Unicode filename using
  // std::fstream in MinGW.
  std::ifstream::open( io::widen( name ).c_str(), mode );
#elif defined( SC_MINGW )
  if ( contains_non_ascii( name ) )
  {
    assert( false && "File Names with non-ascii characters cannot be opened when built with MinGW." );
    return;
  }
  std::ifstream::open( name, mode );
#else
  std::ifstream::open( name, mode );
#endif
}
Exemplo n.º 3
0
/**
 * g_hostname_is_non_ascii:
 * @hostname: a hostname
 *
 * Tests if @hostname contains Unicode characters. If this returns
 * %TRUE, you need to encode the hostname with g_hostname_to_ascii()
 * before using it in non-IDN-aware contexts.
 *
 * Note that a hostname might contain a mix of encoded and unencoded
 * segments, and so it is possible for g_hostname_is_non_ascii() and
 * g_hostname_is_ascii_encoded() to both return %TRUE for a name.
 *
 * Return value: %TRUE if @hostname contains any non-ASCII characters
 *
 * Since: 2.22
 **/
gboolean
g_hostname_is_non_ascii (const gchar *hostname)
{
  return contains_non_ascii (hostname, -1);
}
Exemplo n.º 4
0
/* RFC 3491 IDN cleanup algorithm. */
static gchar *
nameprep (const gchar *hostname,
          gint         len)
{
  gchar *name, *tmp = NULL, *p;

  /* It would be nice if we could do this without repeatedly
   * allocating strings and converting back and forth between
   * gunichars and UTF-8... The code does at least avoid doing most of
   * the sub-operations when they would just be equivalent to a
   * g_strdup().
   */

  /* Remove presentation-only characters */
  name = remove_junk (hostname, len);
  if (name)
    {
      tmp = name;
      len = -1;
    }
  else
    name = (gchar *)hostname;

  /* Convert to lowercase */
  if (contains_uppercase_letters (name, len))
    {
      name = g_utf8_strdown (name, len);
      g_free (tmp);
      tmp = name;
      len = -1;
    }

  /* If there are no UTF8 characters, we're done. */
  if (!contains_non_ascii (name, len))
    {
      if (name == (gchar *)hostname)
        return len == -1 ? g_strdup (hostname) : g_strndup (hostname, len);
      else
        return name;
    }

  /* Normalize */
  name = g_utf8_normalize (name, len, G_NORMALIZE_NFKC);
  g_free (tmp);
  tmp = name;

  if (!name)
    return NULL;

  /* KC normalization may have created more capital letters (eg,
   * angstrom -> capital A with ring). So we have to lowercasify a
   * second time. (This is more-or-less how the nameprep algorithm
   * does it. If tolower(nfkc(tolower(X))) is guaranteed to be the
   * same as tolower(nfkc(X)), then we could skip the first tolower,
   * but I'm not sure it is.)
   */
  if (contains_uppercase_letters (name, -1))
    {
      name = g_utf8_strdown (name, -1);
      g_free (tmp);
      tmp = name;
    }

  /* Check for prohibited characters */
  for (p = name; *p; p = g_utf8_next_char (p))
    {
      if (idna_is_prohibited (g_utf8_get_char (p)))
	{
	  name = NULL;
          g_free (tmp);
	  goto done;
	}
    }

  /* FIXME: We're supposed to verify certain constraints on bidi
   * characters, but glib does not appear to have that information.
   */

 done:
  return name;
}