Esempio n. 1
0
/* check for characters that are invalid in XML */
static gboolean is_valid_string (const gchar * s, gchar * * subst)
{
    if (! g_utf8_validate (s, -1, NULL))
        goto NOT_VALID;

    const gchar * p = s;
    while (* p)
    {
        gunichar c = g_utf8_get_char (p);

        if (IS_VALID_CHAR (c))
            p = g_utf8_next_char (p);
        else
            goto NOT_VALID;
    }

    return TRUE;

NOT_VALID:;
    gint len = 0;

    p = s;
    while (* p)
    {
        gunichar c = g_utf8_get_char_validated (p, -1);

        if (IS_VALID_CHAR (c))
        {
            len += g_unichar_to_utf8 (c, NULL);
            p = g_utf8_next_char (p);
        }
        else
            p ++;
    }

    * subst = g_malloc (len + 1);
    gchar * w = * subst;

    p = s;
    while (* p)
    {
        gunichar c = g_utf8_get_char_validated (p, -1);

        if (IS_VALID_CHAR (c))
        {
            w += g_unichar_to_utf8 (c, w);
            p = g_utf8_next_char (p);
        }
        else
            p ++;
    }

    * w = 0;
    return FALSE;
}
Esempio n. 2
0
void
AppendUCS4ToUTF16(const uint32_t aSource, nsAString& aDest)
{
  NS_ASSERTION(IS_VALID_CHAR(aSource), "Invalid UCS4 char");
  if (IS_IN_BMP(aSource)) {
    aDest.Append(char16_t(aSource));
  } else {
    aDest.Append(H_SURROGATE(aSource));
    aDest.Append(L_SURROGATE(aSource));
  }
}
Esempio n. 3
0
/**
 * Retrieve a possible address (or a part) from an entry box. To make life
 * easier, we only look at the last valid address component; address
 * completion only works at the last string component in the entry box.
 *
 * \param entry Address entry field.
 * \param start_pos Address of start position of address.
 * \return Possible address.
 */
static gchar *get_address_from_edit(GtkEntry *entry, gint *start_pos)
{
	const gchar *edit_text, *p;
	gint cur_pos;
	gboolean in_quote = FALSE;
	gboolean in_bracket = FALSE;
	gchar *str;

	edit_text = gtk_entry_get_text(entry);
	if (edit_text == NULL) return NULL;

	cur_pos = gtk_editable_get_position(GTK_EDITABLE(entry));

	/* scan for a separator. doesn't matter if walk points at null byte. */
	for (p = g_utf8_offset_to_pointer(edit_text, cur_pos);
	     p > edit_text;
	     p = g_utf8_prev_char(p)) {
		if (*p == '"') {
			in_quote = TRUE;
		} else if (!in_quote) {
			if (!in_bracket && *p == ',') {
				break;
			} else if (*p == '<')
				in_bracket = TRUE;
			else if (*p == '>')
				in_bracket = FALSE;
		}
	}

	/* have something valid */
	if (g_utf8_strlen(p, -1) == 0)
		return NULL;

#define IS_VALID_CHAR(x) \
	(g_ascii_isalnum(x) || (x) == '"' || (x) == '<' || (((unsigned char)(x)) > 0x7f))

	/* now scan back until we hit a valid character */
	for (; *p && !IS_VALID_CHAR(*p); p = g_utf8_next_char(p))
		;

#undef IS_VALID_CHAR

	if (g_utf8_strlen(p, -1) == 0)
		return NULL;

	if (start_pos) *start_pos = g_utf8_pointer_to_offset(edit_text, p);

	str = g_strdup(p);

	return str;
} 
static int fget_dtsi_style(unsigned char * buf, int max_num, int fd,off_t *fd_seek)
{
	int cur_seek=*fd_seek;
	unsigned char ch = '\0';
	unsigned char last_char = 'Z';
	int j =0;
	
	sys_lseek(fd, (off_t)0,0);

	while (j < max_num) {
		if ((unsigned)sys_read(fd, &ch, 1) != 1) {
			LCD_LOG_INFO("\n%s: its end of file %d : len = %d\n", __func__, __LINE__, j);
			return j;
		}
		else
		{
			if (!IS_VALID_CHAR(ch)) {
				last_char = 'Z';
				cur_seek++;
				sys_lseek(fd, (off_t)cur_seek,0);
				continue;
			}

			if (last_char != 'Z') {
				/*two char value is possible like F0, so make it a single char*/
				--j;
				buf[j] = (buf[j] * HEX_BASE) + hex_char_to_value(ch);
				last_char = 'Z';
			} else {
				buf[j]= hex_char_to_value(ch);
				last_char = buf[j];
			}

			j++;
			cur_seek++;
			sys_lseek(fd, (off_t)cur_seek,0);
		}
	}

	if (j >= max_num){
		LCD_LOG_ERR("%s:Buffer is not enough", __func__);
		j *= -1;
	}

	*fd_seek=cur_seek;
	return j;
}
Esempio n. 5
0
//
// LoadMap
//
void Raycaster::LoadMap(const char *filename)
{
	int i, j;
	FILE *fp;
	char c, errMsg[MAX_STR_LENGTH];
	
	mapChange = false;
	
	ClearMap();

	doors.clear();
	
	mapH = framework->CountRowsInFile(filename);
	mapW = framework->CountColsInFile(filename);
	
	fp = fopen(filename, "r");
	if(!fp)
	{
		sprintf(errMsg, "Can't load file: %s!", filename);
		framework->Error(errMsg);
	}
	
	for(i=0; i<mapH; i++)
	{
		for(j=0; j<mapW; j++)
		{
			c = fgetc(fp);
			
			while(!IS_VALID_CHAR(c) && !feof(fp))
				c = fgetc(fp);
			
			if(feof(fp) || !IS_VALID_CHAR(c))
				break;
			
			if(c >= '0' && c <= '9')
				map[i][j] = c - '0';			
			else if(c >= 'A' && c <= 'Z')
				map[i][j] = c - 'A' + 10;
			else if(c >= 'a' && c <= 'z')
			{			
				if(c == 'z')
				{
					posX = j + 0.5f;
					posY = i + 0.5f;
					map[i][j] = 0;
				}
				else
					map[i][j] = c - 'a' + 36;
			}
			
			if(map[i][j] == DOOR_INDEX)
			{
				Door door(j, i, this);
				doors.push_back(door);
			}
			else if(map[i][j] == LOCKED_DOOR_INDEX)
			{
				Door door(j, i, this, true);
				doors.push_back(door);
			}
		}
	}
	
	fclose(fp);
}