本文整理汇总了C++中ustring::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ustring::size方法的具体用法?C++ ustring::size怎么用?C++ ustring::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ustring
的用法示例。
在下文中一共展示了ustring::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addString
uint64_t StringTable::addString (ustring str, ustring var_name)
{
ASSERT (m_ptr && "StringTable has not been initialized");
// The strings are laid out in the table as a struct:
//
// struct TableRep {
// size_t len;
// size_t hash;
// char str[len+1];
// };
// Compute the size of the entry before adding it to the table
size_t size = sizeof(size_t) + sizeof(size_t) + str.size() + 1;
if (((m_offset + size) >= m_size)) {
reallocTable();
}
// It should be hard to trigger this assert, unless the table size is
// very small and the string is very large.
ASSERT (m_offset + size <= m_size && "String table allocation error");
int offset = getOffset(str.string());
if (offset < 0) {
// Place the hash and length of the string before the characters
size_t hash = str.hash();
cudaMemcpy (m_ptr + m_offset, (void*)&hash, sizeof(size_t), cudaMemcpyHostToDevice);
m_offset += sizeof(size_t);
size_t len = str.length();
cudaMemcpy (m_ptr + m_offset, (void*)&len, sizeof(size_t), cudaMemcpyHostToDevice);
m_offset += sizeof(size_t);
offset = m_offset;
m_offset_map [str] = offset;
m_name_map [str] = var_name;
// Copy the raw characters to the table
cudaMemcpy (m_ptr + m_offset, str.c_str(), str.size() + 1, cudaMemcpyHostToDevice);
m_offset += str.size() + 1;
// Align the offset for the next entry to 8-byte boundaries
m_offset = (m_offset + 0x7u) & ~0x7u;
}
uint64_t addr = reinterpret_cast<uint64_t>(m_ptr + offset);
// Optionally create an OptiX variable for the string. It's not necessary to
// create a variable for strings that do not appear by name in compiled code
// (in either the OSL library functions or in the renderer).
if (! var_name.empty()) {
m_optix_ctx [var_name.string()]->setUserData (8, &addr);
}
return addr;
}
示例2: filter
ustring
b64_decode (const ustring &message)
{
bool succeeded = false;
auto_BIO mem (BIO_new (BIO_s_mem ()));
auto_BIO filter (BIO_new (BIO_f_base64()));
ustring rv;
BIO_set_flags(((BIO *) filter), BIO_FLAGS_BASE64_NO_NL);
BIO_push (filter, mem);
if ((BIO_write (mem,
message.data (),
message.size ()) >= 0)
&&
(1 == BIO_flush (mem)))
{
const unsigned int Length = BIO_pending (filter);
{
unsigned char *tmp_buf = (unsigned char *) VHTI_alloc (Length);
const int nread = BIO_read(filter, tmp_buf, Length);
if (nread >= 0)
{
succeeded = true;
rv.assign (tmp_buf, nread);
}
free (tmp_buf);
}
}
if (!succeeded)
throw SSL_ERROR;
return rv;
}
示例3: sizeof
void CGlobalRecords::wide2str16(const ustring& str1, u16string& str2)
{
size_t resultSize, inbytesleft, outbytesleft;
const uint8_t *inbuf;
iconv_t cd;
unsigned16_t *outbuf, *origOutbuf = NULL;
cd = iconv_open(UCS_2_INTERNAL, iconv_code.c_str());
// user may have changed the conversion since the workbook was opened
XL_ASSERT(!(cd == (iconv_t)(-1)));
if(cd != (iconv_t)(-1)) {
inbytesleft = str1.size() * sizeof(unichar_t);
outbytesleft = str1.size() * sizeof(unsigned16_t);
inbuf = (uint8_t *)str1.data();
origOutbuf = (unsigned16_t *)calloc(outbytesleft, 1);
outbuf = origOutbuf;
resultSize = iconv(cd, (char **)&inbuf, &inbytesleft, (char **)&outbuf, &outbytesleft);
iconv_close(cd);
} else {
resultSize = (size_t)-1;
}
if(resultSize == (size_t)-1) {
str2 = convFail;
} else {
str2.assign(origOutbuf, (size_t)(outbuf - origOutbuf));
}
free((void *)origOutbuf);
}
示例4: getPubOfPriv
ustring PubAddr::getPubOfPriv(ustring priv)
{
OID CURVE = secp256k1();
ECIES < ECP >::PrivateKey privK;
Integer x;
x.Decode(priv.c_str(), priv.size());
privK.Initialize(CURVE, x);
ECIES<ECP>::PublicKey pub;
privK.MakePublicKey(pub);
string encoded;
int len = pub.GetPublicElement().x.MinEncodedSize();
pub.GetPublicElement().x.Encode(StringSink(encoded).Ref(), len);
len = pub.GetPublicElement().y.MinEncodedSize();
pub.GetPublicElement().y.Encode(StringSink(encoded).Ref(), len);
ustring ret;
ret += 0x04;
ret.fromString(encoded);
return ret;
}
示例5:
TEST(ustring_test, utility) {
for (int i=0;i<(int)hiragana.size();++i) {
EXPECT_TRUE(is_hiragana(hiragana[i]));
EXPECT_FALSE(is_katakana(hiragana[i]));
EXPECT_FALSE(is_kanji(hiragana[i]));
}
for (int i=0;i<(int)katakana.size();++i) {
EXPECT_FALSE(is_hiragana(katakana[i]));
EXPECT_TRUE(is_katakana(katakana[i]));
EXPECT_FALSE(is_kanji(katakana[i]));
}
for (int i=0;i<(int)kanji.size();++i) {
EXPECT_FALSE(is_hiragana(kanji[i]));
EXPECT_FALSE(is_katakana(kanji[i]));
EXPECT_TRUE(is_kanji(kanji[i]));
}
}
示例6: basic_latin_to_zenkaku_latin
ustring basic_latin_to_zenkaku_latin(const ustring& us)
{
ustring res=us;
for (size_t i=0;i<us.size();++i) {
res[i]=basic_latin_to_zenkaku_latin_impl(us[i]);
}
return res;
}
示例7:
ReadNormalizer::ReadNormalizer()
: normalize_map() {
const ustring unnormalized = string_to_ustring(
"ガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッ");
const ustring normalized = string_to_ustring(
"カキクケコサシスセソタチツテトハヒフヘホハヒフヘホアイウエオヤユヤツ");
for (size_t i = 0; i < unnormalized.size(); ++i) {
normalize_map[unnormalized[i]] = normalized[i];
}
}
示例8: replace
ustring replace(ustring source, ustring fromStr, ustring toStr, int offset, int times)
{
int total = 0;
ustring::size_type pos=offset;
while ( ( (pos = source.find(fromStr, pos)) < Glib::ustring::npos) && ( (times==0) || (total++<times) ) )
{
source.replace(pos, fromStr.length(), toStr);
pos+=toStr.size();
}
return source;
}
示例9:
Variant::Variant(const ustring& val) :
Variant()
{
bstrVal = ::SysAllocStringLen(val.c_str(), val.size());
if (bstrVal == nullptr) {
vt = VT_ERROR;
CheckCom(E_OUTOFMEMORY);
} else {
vt = VT_BSTR;
}
}
示例10: GetLineWidth
float CFont::GetLineWidth(const ustring& text, size_t start /*= 0*/)
{
size_t count = text.length()-start;
for (int i = 0; i+start < text.size(); ++i)
{
if (text[i+start] == '\n')
{
count = i;
break;
}
}
return GetStringWidth(text.substr(start, count));
}
示例11: set_lyrics
void set_lyrics(DB_playItem_t *track, ustring lyrics) {
signal_idle().connect_once([track, lyrics = move(lyrics)]() -> void {
const char *artist, *title;
{
pl_lock_guard guard;
if (!is_playing(track))
return;
artist = deadbeef->pl_find_meta(track, "artist");
title = deadbeef->pl_find_meta(track, "title");
}
if (!artist)
artist = _("Unknown Artist");
if (!title)
title = _("Unknown Title");
refBuffer->erase(refBuffer->begin(), refBuffer->end());
refBuffer->insert_with_tags(refBuffer->begin(), title, tagsTitle);
refBuffer->insert_with_tags(refBuffer->end(), ustring("\n") + artist + "\n\n", tagsArtist);
bool italic = false;
bool bold = false;
size_t prev_mark = 0;
vector<RefPtr<TextTag>> tags;
while (prev_mark != ustring::npos) {
size_t italic_mark = lyrics.find("''", prev_mark);
if (italic_mark == ustring::npos)
break;
size_t bold_mark = ustring::npos;
if (italic_mark < lyrics.size() - 2 && lyrics[italic_mark + 2] == '\'')
bold_mark = italic_mark;
tags.clear();
if (italic) tags.push_back(tagItalic);
if (bold) tags.push_back(tagBold);
refBuffer->insert_with_tags(refBuffer->end(),
lyrics.substr(prev_mark, min(bold_mark, italic_mark) - prev_mark), tags);
if (bold_mark == ustring::npos) {
prev_mark = italic_mark + 2;
italic = !italic;
} else {
prev_mark = bold_mark + 3;
bold = !bold;
}
}
refBuffer->insert(refBuffer->end(), lyrics.substr(prev_mark)); // in case if no formatting found
last = track;
});
}
示例12: search_equal
bool PluginDisplay::search_equal(const Glib::RefPtr<Gtk::TreeModel>& model, int column, const ustring& key, const Gtk::TreeIter& iter) {
PluginDesc *p = iter->get_value(plugin_liststore->col.pdesc);
ustring txt(gx_system::to_string(p->UniqueID));
if (txt.compare(0, ustring::npos, key, 0, key.size()) == 0) {
return false;
}
txt = iter->get_value(plugin_liststore->col.name).lowercase();
std::vector<ustring> keyvec;
split(keyvec, key);
for (std::vector<ustring>::iterator i = keyvec.begin(); i != keyvec.end(); ++i) {
if (txt.find(*i) == ustring::npos) {
return true;
}
}
return false;
}
示例13: hankaku_to_zenkaku
ustring hankaku_to_zenkaku(const ustring& ustr){
ustring res;
for (size_t i=0;i<ustr.size();++i) {
uchar c=res.size()>0?res[res.size()-1]:0xFFFFFFFFU;
if (is_hankaku(ustr[i])) {
if (ustr[i]==UTF_HANKAKU_DAKUTEN) {
if (c!=0xFFFFFFFFU&&is_katakana(c)&&take_dakuten_tbl[c-0x30a0]) {
if (c==0x30a6) { // ウ
res[res.size()-1]=0x30f4;
} else if (c==0x30f2) { // ヲ
res[res.size()-1]=0x30fa;
} else {
++res[res.size()-1];
}
} else {
res.push_back(UTF_ZENKAKU_DAKUTEN); // zenkaku dakuten
}
} else if (ustr[i]==UTF_HANKAKU_HANDAKUTEN) {
if (c!=0xFFFFFFFFU&&is_katakana(c)&&take_handakuten_tbl[c-0x30a0]) {
res[res.size()-1]+=2;
} else {
res.push_back(UTF_ZENKAKU_HANDAKUTEN); // zenkaku dakuten
}
} else {
res.push_back(hankaku_zenkaku_tbl[ustr[i]-0xff60]);
}
} else if (ustr[i]==UTF_HANKAKU_BAR) { // -
if (c!=0xFFFFFFFFU&&!is_basic_latin(c)) {
res.push_back(UTF_ZENKAKU_BAR);
} else {
res.push_back(ustr[i]);
}
} else {
res.push_back(ustr[i]);
}
}
return res;
}
示例14: convert
bool IConvert::convert(const ustring& from,string& to) {
assert(!from.empty());
size_t insize = 0;
size_t outsize = 0;
iconv(m_iconv_from_unicode, NULL, &insize, NULL, &outsize);
insize = from.size() * sizeof(uchar_t);
outsize = BUFFER_SIZE;
size_t ret;
char* psrc = (char*)from.data();
char* pdest = m_buffer;
ret = iconv(m_iconv_from_unicode, &psrc, &insize, &pdest, &outsize);
if (ret == (size_t)(-1))
return false;
else {
to.assign(m_buffer,pdest);
//to.assign(m_buffer,(BUFFER_SIZE - outsize)/sizeof(char));
return true;
}
}
示例15: decode
ustring PubAddr::decode(ustring data, ustring privK)
{
unsigned int p = 0;
ustring IV = data.getUstring(16, p);
unsigned int curveType = data.getInt16(p);
unsigned int Xlen = data.getInt16(p);
ustring X = data.getUstring(Xlen, p);
unsigned int Ylen = data.getInt16(p);
ustring Y = data.getUstring(Ylen, p);
ustring cipherText = data.getUstring(data.size() - (p + 32), p);
ustring MAC = data.getUstring(32, p);
ustring pubK;
pubK += 0x04;
pubK += X;
pubK += Y;
OID CURVE = secp256k1();
AutoSeededRandomPool rng;
ECDH < ECP >::Domain dhA(CURVE), dhB(CURVE);
SecByteBlock privA(privK.c_str(), dhA.PrivateKeyLength());
SecByteBlock pubB(pubK.c_str(), dhB.PublicKeyLength());
if (dhA.AgreedValueLength() != dhB.AgreedValueLength())
{
throw runtime_error("Shared shared size mismatch");
}
SecByteBlock sharedA(dhA.AgreedValueLength()), sharedB(dhB.AgreedValueLength());
if (!dhA.Agree(sharedA, privA, pubB))
throw runtime_error("Failed to reach shared secret (A)");
Integer ssa, ssb;
ssa.Decode(sharedA.BytePtr(), sharedA.SizeInBytes());
uint8_t H[CryptoPP::SHA512::DIGESTSIZE];
CryptoPP::SHA512 hash;
hash.CalculateDigest(H, sharedA.BytePtr(), sharedA.SizeInBytes());
AutoSeededRandomPool prng;
byte key[32];
memcpy(key, H, sizeof(key));
byte Hkey[32];
memcpy(Hkey, &(H[32]), sizeof(Hkey));
byte iv[16];
memcpy(iv, IV.c_str(), IV.size());
string cipher = cipherText.toString(), encoded, recovered;
string HMacPlain;
p = 0;
HMacPlain += data.getString(data.size()-32,p);
string mac;
try
{
HMAC<SHA256> hmac(Hkey, 32);
StringSource s(HMacPlain, true,
new HashFilter(hmac,
new StringSink(mac)
)
);
}
catch (const CryptoPP::Exception& e)
{
throw runtime_error(e.what());
}
if (mac != MAC.toString())
throw runtime_error("mac doesnt match");
try
{
CBC_Mode< AES >::Decryption d;
d.SetKeyWithIV(key, sizeof(key), iv);
// The StreamTransformationFilter removes
// padding as required.
StringSource s(cipher, true,
new StreamTransformationFilter(d,
new StringSink(recovered)
) // StreamTransformationFilter
); // StringSource
}
//.........这里部分代码省略.........