Exemple #1
0
void file_info::meta_set(const char * name,const char * value)	//deletes all fields of given name (if any), then adds new one
{
	assert(is_valid_utf8(name));
	assert(is_valid_utf8(value));
	meta_remove_field(name);
	meta_add(name,value);
}
Exemple #2
0
const char * file_info::meta_get(const char * name,int num) const
{
	assert(is_valid_utf8(name));
	int idx = meta_get_idx(name,num);
	if (idx<0) return 0;
	else return meta_enum_value(idx);
}
Exemple #3
0
__int64 file_info::info_get_int(const char * name) const
{
	assert(is_valid_utf8(name));
	const char * val = info_get(name);
	if (val==0) return 0;
	return _atoi64(val);
}
Exemple #4
0
void
FindTextView::Copy(BClipboard* clipboard)
{
	if (fMode != kHexMode) {
		BTextView::Copy(clipboard);
		return;
	}

	int32 start, end;
	GetSelection(&start, &end);

	if (clipboard == NULL || start == end)
		return;

	AutoLocker<BClipboard> _(clipboard);

	BMessage* clip = clipboard->Data();
	if (clip == NULL)
		return;

	// convert hex-text to real data
	uint8* data;
	size_t dataSize;
	if (_GetDataFromHex(Text() + start, end - start, &data, &dataSize)
			!= B_OK)
		return;

	clip->AddData(B_FILE_MIME_TYPE, B_MIME_TYPE, data, dataSize);

	if (is_valid_utf8(data, dataSize))
		clip->AddData("text/plain", B_MIME_TYPE, data, dataSize);

	free(data);
}
Exemple #5
0
int
main (void) {

  struct Tester tests[] = { 
                           {"\xc3\xb1", true},
                           {"\xe2\x28\xa1", false},
                           {"Hello, World!", true},
                           {"\xf0\x28\x8c\x28", false},
                           {"\xE2\x98\x82\xE2\x98\x83", true},
                           {"\xf0\x28\x8c\xbc", false},
                           {"\xe2\x28\x28", false},
                           {"\xc3\x28" , false},
                           {"", true},
                           {"   ", true},
                           {"\x80", false}
                         };

  int end = sizeof(tests) / sizeof(tests[0]);
  for (int i = 0; i < end; i++) {

    const char *string = tests[i].string;
    int size = strlen(string);

    const char *result = (is_valid_utf8(string, size) == tests[i].valid) ? "Pass" : "Fail";
    printf("%d: %s\n", i, result);
  }

  return 0;
}
Exemple #6
0
void file_info::info_set_int(const char * name,__int64 value)
{
	assert(is_valid_utf8(name));
	char temp[32];
	_i64toa(value,temp,10);
	info_set(name,temp);
}
Exemple #7
0
const char * file_info::info_get(const char * name) const
{
	assert(is_valid_utf8(name));
	int idx = info_get_idx(name);
	if (idx<0) return 0;
	else return info_enum_value(idx);
}
Exemple #8
0
static int nick_is_utf8(const char* nick)
{
	/*
	 * Nick should be valid utf-8, but
	 * perhaps we should check if the nick is unicode normalized?
	 */
	if (!is_valid_utf8(nick))
		return nick_invalid_bad_utf8;
	return nick_ok;
}
Exemple #9
0
int file_info::info_get_idx(const char * name) const
{
	assert(is_valid_utf8(name));
	int n,m=info_get_count();
	for(n=0;n<m;n++)
	{
		if (!stricmp_utf8(name,info_enum_name(n)))
			return n;
	}
	return -1;
}
Exemple #10
0
void file_info::meta_remove_field(const char * name)//removes ALL fields of given name
{
	assert(is_valid_utf8(name));
	int n;
	for(n=meta_get_count()-1;n>=0;n--)
	{
		if (!stricmp_utf8(meta_enum_name(n),name))
			meta_remove(n);
	}

}
Exemple #11
0
void file_info::info_remove_field(const char * name)
{
	assert(is_valid_utf8(name));
	int n;
	for(n=info_get_count()-1;n>=0;n--)
	{
		if (!stricmp_utf8(name,info_enum_name(n)))
			info_remove(n);
	}

}
Exemple #12
0
int file_info::meta_get_count_by_name(const char* name) const
{
	assert(is_valid_utf8(name));
	int n,m=meta_get_count();
	int rv=0;
	for(n=0;n<m;n++)
	{
		if (!stricmp_utf8(name,meta_enum_name(n)))
			rv++;
	}
	return rv;
}
Exemple #13
0
void file_info::info_set_float(const char * name,double value,unsigned precision,bool force_sign,const char * unit)
{
	assert(is_valid_utf8(name));
	assert(unit==0 || strlen(unit) <= 64);
	char temp[128];
	pfc_float_to_string(temp,value,precision,force_sign);
	if (unit)
	{
		strcat(temp," ");
		strcat(temp,unit);
	}
	info_set(name,temp);
}
Exemple #14
0
int file_info::meta_get_idx(const char * name,int num) const
{
	assert(is_valid_utf8(name));
	int n,m=meta_get_count();
	for(n=0;n<m;n++)
	{
		if (!stricmp_utf8(name,meta_enum_name(n)))
		{
			if (num==0) return n;
			num--;
		}
	}
	return -1;
}
Exemple #15
0
static int config_parse_line(char* line, int line_count, void* ptr_data)
{
	char* pos;
	char* key;
	char* data;
	struct hub_config* config = (struct hub_config*) ptr_data;

	strip_off_ini_line_comments(line, line_count);

	if (!*line) return 0;

	LOG_DUMP("config_parse_line(): '%s'", line);

	if (!is_valid_utf8(line))
	{
		LOG_WARN("Invalid utf-8 characters on line %d", line_count);
	}

	if ((pos = strchr(line, '=')) != NULL)
	{
		pos[0] = 0;
	}
	else
	{
		return 0;
	}

	key = line;
	data = &pos[1];

	key = strip_white_space(key);
	data = strip_white_space(data);
	data = strip_off_quotes(data);

	if (!*key || !*data)
	{
		LOG_FATAL("Configuration parse error on line %d", line_count);
		return -1;
	}

	LOG_DUMP("config_parse_line: '%s' => '%s'", key, data);

	return apply_config(config, key, data, line_count);
}
Exemple #16
0
void
DataView::InitiateDrag(view_focus focus)
{
	BMessage *drag = new BMessage(B_MIME_DATA);

	// Add originator and action
	drag->AddPointer("be:originator", this);
	//drag->AddString("be:clip_name", "Byte Clipping");
	//drag->AddInt32("be_actions", B_TRASH_TARGET);

	// Add data (just like in Copy())
	uint8 *data = fData + fStart;
	size_t length = fEnd + 1 - fStart;

	drag->AddData(B_FILE_MIME_TYPE, B_MIME_TYPE, data, length);
	if (is_valid_utf8(data, length))
		drag->AddData("text/plain", B_MIME_TYPE, data, length);

	// get a frame that contains the whole selection - SelectionFrame()
	// only spans a rectangle between the start and the end point, so
	// we have to pass it the correct input values

	BRect frame;
	const int32 width = kBlockSize - 1;
	int32 first = fStart & ~width;
	int32 last = ((fEnd + width) & ~width) - 1;
	if (first == (last & ~width))
		frame = SelectionFrame(focus, fStart, fEnd);
	else
		frame = SelectionFrame(focus, first, last);

	BRect bounds = Bounds();
	if (!bounds.Contains(frame))
		frame = bounds & frame;

	DragMessage(drag, frame, NULL);

	fStoredStart = fStart;
	fStoredEnd = fEnd;
	fDragMessageSize = length;
}
Exemple #17
0
void
DataView::Copy()
{
	if (!be_clipboard->Lock())
		return;

	be_clipboard->Clear();

	BMessage *clip;
	if ((clip = be_clipboard->Data()) != NULL) {
		uint8 *data = fData + fStart;
		size_t length = fEnd + 1 - fStart;

		clip->AddData(B_FILE_MIME_TYPE, B_MIME_TYPE, data, length);

		if (is_valid_utf8(data, length))
			clip->AddData("text/plain", B_MIME_TYPE, data, length);

		be_clipboard->Commit();
	}

	be_clipboard->Unlock();
}
Exemple #18
0
static enum rules_token
lex(struct scanner *s, union lvalue *val)
{
skip_more_whitespace_and_comments:
    /* Skip spaces. */
    while (is_space(peek(s)))
        if (next(s) == '\n')
            return TOK_END_OF_LINE;

    /* Skip comments. */
    if (chr(s, '#')) {
        skip_to_eol(s);
        goto skip_more_whitespace_and_comments;
    }

    /* See if we're done. */
    if (eof(s)) return TOK_END_OF_FILE;

    /* New token. */
    s->token_line = s->line;
    s->token_column = s->column;
    s->buf_pos = 0;

    /* LHS Keysym. */
    if (chr(s, '<')) {
        while (peek(s) != '>' && !eol(s))
            buf_append(s, next(s));
        if (!chr(s, '>')) {
            scanner_err(s, "unterminated keysym literal");
            return TOK_ERROR;
        }
        if (!buf_append(s, '\0')) {
            scanner_err(s, "keysym literal is too long");
            return TOK_ERROR;
        }
        val->string.str = s->buf;
        val->string.len = s->buf_pos;
        return TOK_LHS_KEYSYM;
    }

    /* Colon. */
    if (chr(s, ':'))
        return TOK_COLON;
    if (chr(s, '!'))
        return TOK_BANG;
    if (chr(s, '~'))
        return TOK_TILDE;

    /* String literal. */
    if (chr(s, '\"')) {
        while (!eof(s) && !eol(s) && peek(s) != '\"') {
            if (chr(s, '\\')) {
                uint8_t o;
                if (chr(s, '\\')) {
                    buf_append(s, '\\');
                }
                else if (chr(s, '"')) {
                    buf_append(s, '"');
                }
                else if (chr(s, 'x') || chr(s, 'X')) {
                    if (hex(s, &o))
                        buf_append(s, (char) o);
                    else
                        scanner_warn(s, "illegal hexadecimal escape sequence in string literal");
                }
                else if (oct(s, &o)) {
                    buf_append(s, (char) o);
                }
                else {
                    scanner_warn(s, "unknown escape sequence (%c) in string literal", peek(s));
                    /* Ignore. */
                }
            } else {
                buf_append(s, next(s));
            }
        }
        if (!chr(s, '\"')) {
            scanner_err(s, "unterminated string literal");
            return TOK_ERROR;
        }
        if (!buf_append(s, '\0')) {
            scanner_err(s, "string literal is too long");
            return TOK_ERROR;
        }
        if (!is_valid_utf8(s->buf, s->buf_pos - 1)) {
            scanner_err(s, "string literal is not a valid UTF-8 string");
            return TOK_ERROR;
        }
        val->string.str = s->buf;
        val->string.len = s->buf_pos;
        return TOK_STRING;
    }

    /* Identifier or include. */
    if (is_alpha(peek(s)) || peek(s) == '_') {
        s->buf_pos = 0;
        while (is_alnum(peek(s)) || peek(s) == '_')
            buf_append(s, next(s));
        if (!buf_append(s, '\0')) {
            scanner_err(s, "identifier is too long");
            return TOK_ERROR;
        }

        if (streq(s->buf, "include"))
            return TOK_INCLUDE;

        val->string.str = s->buf;
        val->string.len = s->buf_pos;
        return TOK_IDENT;
    }

    /* Discard rest of line. */
    skip_to_eol(s);

    scanner_err(s, "unrecognized token");
    return TOK_ERROR;
}