本文整理汇总了C++中CharArray类的典型用法代码示例。如果您正苦于以下问题:C++ CharArray类的具体用法?C++ CharArray怎么用?C++ CharArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CharArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shaderSource
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
String ShaderSourceRepository::shaderSource(ShaderIdent shaderIdent)
{
String shaderProg;
CharArray rawSource;
if (rawShaderSource(shaderIdent, &rawSource))
{
if (rawSource.size() > 0)
{
#ifdef CVF_OPENGL_ES
// Always version 100 on OpenGL ES
shaderProg = "#version 100\nprecision highp float;\n";
#else
// Default on desktop is GLSL 1.2 (OpenGL 2.1) unless the shader explicitly specifies a version
if (rawSource[0] != '#')
{
shaderProg = "#version 120\n";
}
#endif
shaderProg += rawSource.ptr();
}
}
return shaderProg;
}
示例2: test_set_byte
void test_set_byte() {
CharArray* c = String::create(state, "xyz")->data();
c->set_byte(state, Fixnum::from(0), Fixnum::from('1'));
TS_ASSERT_EQUALS(c->get_byte(state, Fixnum::from(0)), Fixnum::from('1'));
c->set_byte(state, Fixnum::from(2), Fixnum::from('2'));
TS_ASSERT_EQUALS(c->get_byte(state, Fixnum::from(2)), Fixnum::from('2'));
}
示例3: rd
value_t Hash::to_s(Hash *self)
{
RecursionDetector<RecursionType::Hash_to_s, false> rd(self);
if(rd.recursion())
return String::get("{...}");
CharArray result = "{";
OnStack<1> os1(self);
OnStackString<1> os2(result);
HashAccess::each_pair(self, [&](value_t key, value_t value) -> bool {
OnStack<1> os(value);
result += inspect(key);
result += "=>";
result += inspect(value);
result += ", ";
return true;
});
if(result.size() > 1)
result.shrink(result.size() - 2);
result += "}";
return result.to_string();
}
示例4: finally
value_t IO::rb_readlines(String *path)
{
Stream *file;
Platform::wrap([&] {
file = Platform::open(path->string, Platform::Read, Platform::Open);
});
Finally finally([&] {
delete file;
});
auto result = Array::allocate();
while(true)
{
CharArray line = file->gets();
if(line.size())
result->vector.push(line.to_string());
else
break;
}
return result;
}
示例5: if
String* String::resize_capacity(STATE, Fixnum* count) {
native_int sz = count->to_native();
if(sz < 0) {
Exception::argument_error(state, "negative byte array size");
} else if(sz >= INT32_MAX) {
// >= is used deliberately because we use a size of + 1
// for the byte array
Exception::argument_error(state, "too large byte array size");
}
CharArray* ba = CharArray::create(state, sz + 1);
native_int copy_size = sz;
native_int data_size = as<CharArray>(data_)->size();
// Check that we don't copy any data outside the existing byte array
if(unlikely(copy_size > data_size)) {
copy_size = data_size;
}
memcpy(ba->raw_bytes(), byte_address(), copy_size);
// We've unshared
shared(state, Qfalse);
data(state, ba);
hash_value(state, nil<Fixnum>());
// If we shrunk it and num_bytes said there was more than there
// is, clamp it.
if(num_bytes()->to_native() > sz) {
num_bytes(state, count);
}
return this;
}
示例6: test_to_chars
void test_to_chars() {
String* s = String::create(state, "xy");
CharArray* c = s->data();
char* chars = c->to_chars(state, Fixnum::from(2));
TS_ASSERT_SAME_DATA("xy", chars, 2);
}
示例7: get_UserInfo
void IL2Client::game_TargetByName( const wchar_t *name )
{
//L2Client *cl = (L2Client *)m_pcl;
UserInfo *usr = get_UserInfo();
CharArray *ca = get_WorldChars();
NpcArray *na = get_WorldNpcs();
unsigned int nPassed = 0, i = 0, count = ca->GetCount();
unsigned int objectID = 0;
if( _wcsicmp( name, usr->charName ) == 0 )
{
objectID = usr->objectID;
}
if( objectID == 0 )
{
// try chars
count = ca->GetCount();
nPassed = 0;
if( count > 0 )
{
ca->Lock();
for( i=0; i<CharArray::CHARARRAY_MAX_CHARS; i++ )
{
if( ca->chars_array[i]->isUnused() ) continue;
nPassed++;
if( _wcsicmp( name, ca->chars_array[i]->charName ) == 0 )
{
objectID = ca->chars_array[i]->objectID;
break;
}
if( nPassed >= count ) break;
}
ca->Unlock();
}
}
if( objectID == 0 )
{
// try NPCs
count = na->getCount();
nPassed = 0;
if( count > 0 )
{
na->Lock();
for( i=0; i<NpcArray::NPCA_MAX_NPCS; i++ )
{
if( na->npcs_array[i]->isUnused() ) continue;
nPassed++;
if( _wcsicmp( name, na->npcs_array[i]->charName ) == 0 )
{
objectID = na->npcs_array[i]->objectID;
break;
}
if( nPassed >= count ) break;
}
na->Unlock();
}
}
if( objectID == 0 ) return;
game_Action( objectID );
}
示例8: toUnicode
int32_t StringUtils::toUnicode(const uint8_t* utf8, int32_t length, CharArray unicode)
{
if (length == 0)
return 0;
UTF8Decoder utf8Decoder(utf8, utf8 + length);
int32_t decodeLength = utf8Decoder.decode(unicode.get(), unicode.size());
return decodeLength == Reader::READER_EOF ? 0 : decodeLength;
}
示例9: test_get_byte_index_out_of_bounds
void test_get_byte_index_out_of_bounds() {
CharArray* c = String::create(state, "xyz")->data();
native_int sz = c->size(state)->to_native();
TS_ASSERT_THROWS_ASSERT(c->get_byte(state, Fixnum::from(sz)), const RubyException &e,
TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
TS_ASSERT_THROWS_ASSERT(c->get_byte(state, Fixnum::from(sz+1)), const RubyException &e,
TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
TS_ASSERT_THROWS_ASSERT(c->get_byte(state, Fixnum::from(-1)), const RubyException &e,
TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
}
示例10: test_compare_bytes_out_of_bounds
void test_compare_bytes_out_of_bounds() {
CharArray* a = String::create(state, "xyZzy")->data();
CharArray* b = String::create(state, "xyzzy")->data();
Fixnum* zero = Fixnum::from(0);
Fixnum* neg = Fixnum::from(-1);
TS_ASSERT_THROWS_ASSERT(a->compare_bytes(state, b, neg, zero), const RubyException &e,
TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
TS_ASSERT_THROWS_ASSERT(a->compare_bytes(state, b, zero, neg), const RubyException &e,
TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
}
示例11: while
CharArray Stream::gets()
{
static const size_t buffer_size = 0x200;
CharArray result, buffer;
while(true)
{
pos_t p = pos();
buffer = read(buffer_size);
for(size_t i = 0; i < buffer.size(); ++i)
{
if(buffer[i] == '\r')
{
++i;
if(i < buffer.size())
{
if(buffer[i] == '\n')
++i;
seek(p + i, FromStart);
return result + buffer.copy(0, i);
}
else
{
CharArray c = read(1);
if(c == "\n")
buffer += c;
else
seek(-(pos_t)c.size());
return result + buffer;
}
}
else if(buffer[i] == '\n')
{
++i;
seek(p + i, FromStart);
return result + buffer.copy(0, i);
}
}
if(buffer.size() < buffer_size)
return result + buffer;
result += buffer;
}
}
示例12: read
CharArray NativeStream::read(size_t length)
{
CharArray buf;
buf.buffer(length);
ssize_t result = ::read(fd, buf.str_ref(), buf.size());
if(result < 0)
raise("Unable to read from file descriptor");
buf.shrink((size_t)result);
return buf;
}
示例13: ArgumentNullException
ByteArray Convert::FromBase64CharArray(CharArray& inArray, int offset, int length)
{
if(inArray.IsNull())
throw ArgumentNullException(L"inArray");
if(offset < 0)
throw ArgumentOutOfRangeException(L"offset < 0");
if(length < 0)
throw ArgumentOutOfRangeException(L"length < 0");
// avoid integer overflow
if(offset > (int)inArray.Length() - length)
throw ArgumentOutOfRangeException(L"offset + length > array.Length");
return InternalFromBase64CharArray(inArray, offset, length);
}
示例14: TEST_F
TEST_F(MappingCharFilterTest, testReaderReset) {
CharStreamPtr cs = newLucene<MappingCharFilter>(normMap, newLucene<StringReader>(L"x"));
CharArray buf = CharArray::newInstance(10);
int32_t len = cs->read(buf.get(), 0, 10);
EXPECT_EQ(1, len);
EXPECT_EQ(L'x', buf[0]) ;
len = cs->read(buf.get(), 0, 10);
EXPECT_EQ(-1, len);
// rewind
cs->reset();
len = cs->read(buf.get(), 0, 10);
EXPECT_EQ(1, len);
EXPECT_EQ(L'x', buf[0]) ;
}
示例15: split
template<typename F1, typename F2> void split(const CharArray &input, F1 data, F2 split)
{
compile_pattern();
int ovector[vector_size];
size_t prev = 0;
while(true)
{
int groups = match(input, ovector, prev);
if(groups <= 0)
{
if(prev < input.size())
data(input.copy(prev, input.size() - prev));
return;
}
else
{
int start = ovector[0];
int stop = ovector[1];
for (int i = 0; i < groups; i++) {
start = std::min(start, ovector[2 * i]);
stop = std::max(stop, ovector[2 * i + 1]);
}
if((size_t)stop == prev)
{
split(start, stop);
data(input.copy(prev, 1));
prev += 1;
}
else
{
data(input.copy(prev, (size_t)start - prev));
split(start, stop);
prev = stop;
}
}
}
}