本文整理汇总了C++中NarrowString类的典型用法代码示例。如果您正苦于以下问题:C++ NarrowString类的具体用法?C++ NarrowString怎么用?C++ NarrowString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NarrowString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unsigned
bool
LX16xxConfigWidget::SaveFixedEnumSetting(LX1600::Setting key, unsigned idx,
LX1600::SettingsMap &settings,
unsigned factor)
{
const std::string old_value = device.GetLX16xxSetting(key);
unsigned value = unsigned(ParseDouble(old_value.c_str()) * factor);
if (!SaveValue(idx, value))
return false;
NarrowString<32> buffer;
buffer.UnsafeFormat("%.2f", (double)value / factor);
settings[key] = std::string(buffer.c_str(), buffer.end());
return true;
}
示例2: narrow_value
bool
FlarmDevice::SetConfig(const char *setting, const TCHAR *value)
{
NarrowPathName narrow_value(value);
NarrowString<256> buffer;
buffer.Format("PFLAC,S,%s,", setting);
buffer.append(narrow_value);
NarrowString<256> expected_answer(buffer);
expected_answer[6u] = 'A';
Send(buffer);
return port.ExpectString(expected_answer);
}
示例3: expected_answer
bool
FlarmDevice::GetConfig(const char *setting, char *buffer, size_t length,
OperationEnvironment &env)
{
NarrowString<90> request;
request.Format("PFLAC,R,%s", setting);
NarrowString<90> expected_answer(request);
expected_answer[6u] = 'A';
expected_answer.push_back(',');
Send(request, env);
return Receive(expected_answer, buffer, length,
env, std::chrono::seconds(2));
}
示例4: WriteEventAttributes
static void
WriteEventAttributes(TextWriter &writer,
const BrokenDateTime &time, const GeoPoint &location)
{
JSON::ObjectWriter object(writer);
if (time.IsPlausible()) {
NarrowString<64> buffer;
FormatISO8601(buffer.buffer(), time);
object.WriteElement("time", JSON::WriteString, buffer);
}
if (location.IsValid())
JSON::WriteGeoPointAttributes(object, location);
}
示例5: main
int main(int argc, char **argv)
{
NarrowString<1024> usage;
usage = "DRIVER\n\n"
"Where DRIVER is one of:";
{
const DeviceRegister *driver;
for (unsigned i = 0; (driver = GetDriverByIndex(i)) != nullptr; ++i) {
WideToUTF8Converter driver_name(driver->name);
usage.AppendFormat("\n\t%s", (const char *)driver_name);
}
}
Args args(argc, argv, usage);
tstring driver_name = args.ExpectNextT();
args.ExpectEnd();
driver = FindDriverByName(driver_name.c_str());
if (driver == nullptr) {
_ftprintf(stderr, _T("No such driver: %s\n"), driver_name.c_str());
return 1;
}
DeviceConfig config;
config.Clear();
NullPort port;
Device *device = driver->CreateOnPort != nullptr
? driver->CreateOnPort(config, port)
: nullptr;
NMEAParser parser;
NMEAInfo data;
data.Reset();
char buffer[1024];
while (fgets(buffer, sizeof(buffer), stdin) != nullptr) {
StripRight(buffer);
if (device == nullptr || !device->ParseNMEA(buffer, data))
parser.ParseLine(buffer, data);
}
Dump(data);
return EXIT_SUCCESS;
}
示例6: ASSERT
/**
* Constructs a secure random number generator (RNG) implementing the named
* random number algorithm.
*/
SecureRandomBase::SecureRandomBase(const NarrowString& algorithm, const byte*, size_t)
: m_catastrophic(false), m_algorithm(algorithm)
{
ASSERT( !algorithm.empty() );
//ASSERT(seed);
//ASSERT(size);
}
示例7: isAllowedCipherMode
/**
* Return true if specified cipher mode may be used for encryption and
* decryption operations via {@link org.owasp.esapi.Encryptor}.
* @param cipherMode The specified cipher mode to be used for the encryption
* or decryption operation.
* @return true if the specified cipher mode is in the comma-separated list
* of cipher modes supporting both confidentiality and authenticity;
* otherwise false.
* @see #isCombinedCipherMode(String)
* @see org.owasp.esapi.SecurityConfiguration#getCombinedCipherModes()
* @see org.owasp.esapi.SecurityConfiguration#getAdditionalAllowedCipherModes()
*/
bool CryptoHelper::isAllowedCipherMode(const NarrowString& cipherMode)
{
ESAPI_ASSERT2( !cipherMode.empty(), "cipherMode is not valid" );
if(cipherMode.empty())
throw IllegalArgumentException("Cipher mode is not valid");
if ( isCombinedCipherMode(cipherMode) ) {
return true;
}
DummyConfiguration config;
const StringList& extraModes = config.getAdditionalAllowedCipherModes();
StringList::const_iterator it = std::find(extraModes.begin(), extraModes.end(), cipherMode);
return it != extraModes.end();
}
示例8: ASSERT
/**
* Constructs a secure random number generator (RNG) implementing the named
* random number algorithm if specified
*/
SecureRandom::SecureRandom(const NarrowString& algorithm)
: m_lock(new Mutex),
m_impl(SecureRandomBase::createInstance(AlgorithmName::normalizeAlgorithm(algorithm), nullptr, 0))
{
ASSERT( !algorithm.empty() );
ASSERT(m_lock.get() != nullptr);
ASSERT(m_impl.get() != nullptr);
}
示例9: getFirstToken
bool getFirstToken (const NarrowString & str, size_t pos, size_t & endpos, NarrowString & token, const char * sepChars)
{
const size_t first_nonspace = str.find_first_not_of ( sepChars, pos );
if (first_nonspace != std::string::npos)
{
const size_t first_space = str.find_first_of (sepChars, first_nonspace );
if (first_space != std::string::npos)
token = str.substr (first_nonspace, first_space - first_nonspace);
else
token = str.substr (first_nonspace);
endpos = first_space;
return true;
}
else
return false;
}
示例10: assert
bool
LiveTrack24::Client::GenerateSessionID(const TCHAR *_username, const TCHAR *_password,
OperationEnvironment &env)
{
// http://www.livetrack24.com/client.php?op=login&user=<username>&pass=<pass>
assert(_username != NULL);
assert(!StringIsEmpty(_username));
assert(_password != NULL);
assert(!StringIsEmpty(_password));
const WideToUTF8Converter username2(_username);
const WideToUTF8Converter password2(_password);
if (!username2.IsValid() || !password2.IsValid())
return false;
NarrowString<1024> url;
url.Format("http://%s/client.php?op=login&user=%s&pass=%s",
(const char *)server, (const char *)username2, (const char *)_password);
// Open download session
Net::Session session;
// Request the file
char buffer[1024];
size_t size = Net::DownloadToBuffer(session, url, buffer, sizeof(buffer) - 1,
env);
if (size == 0 || size == size_t(-1))
return false;
buffer[size] = 0;
char *p_end;
UserID user_id = strtoul(buffer, &p_end, 10);
if (buffer == p_end) {
return false;
}
username.SetASCII(_username);
password.SetASCII(_password);
session_id = RandomSessionID();
session_id |= (user_id & 0x00ffffff);
return true;
}
示例11: expected_answer
bool
FlarmDevice::GetConfig(const char *setting, TCHAR *buffer, size_t length)
{
NarrowString<256> request;
request.Format("PFLAC,R,%s", setting);
NarrowString<256> expected_answer(request);
expected_answer[6u] = 'A';
expected_answer += ',';
char narrow_buffer[length];
Send(request);
if (!Receive(expected_answer, narrow_buffer, length, 1000))
return false;
_tcscpy(buffer, PathName(narrow_buffer));
return true;
}
示例12:
bool
FLARMConfigWidget::Save(bool &_changed)
{
PopupOperationEnvironment env;
bool changed = false;
NarrowString<32> buffer;
if (SaveValue(Baud, baud)) {
buffer.UnsafeFormat("%u", baud);
device.SendSetting("BAUD", buffer, env);
changed = true;
}
if (SaveValue(Priv, priv)) {
buffer.UnsafeFormat("%u", priv);
device.SendSetting("PRIV", buffer, env);
changed = true;
}
if (SaveValue(Thre, thre)) {
buffer.UnsafeFormat("%u", thre);
device.SendSetting("THRE", buffer, env);
changed = true;
}
if (SaveValue(Range, range)) {
buffer.UnsafeFormat("%u", range);
device.SendSetting("RANGE", buffer, env);
changed = true;
}
if (SaveValue(Acft, acft)) {
buffer.UnsafeFormat("%u", acft);
device.SendSetting("ACFT", buffer, env);
changed = true;
}
if (SaveValue(LogInt, log_int)) {
buffer.UnsafeFormat("%u", log_int);
device.SendSetting("LOGINT", buffer, env);
changed = true;
}
if (SaveValue(NoTrack, notrack)) {
buffer.UnsafeFormat("%u", notrack);
device.SendSetting("NOTRACK", buffer, env);
changed = true;
}
_changed |= changed;
return true;
}
示例13: generateSecretKey
/**
* Generate a random secret key appropriate to the specified cipher algorithm
* and key size.
* @param alg The cipher algorithm or cipher transformation. (If the latter is
* passed, the cipher algorithm is determined from it.) Cannot be empty.
* @param keyBits The key size, in bits.
* @return A random {@code SecretKey} is returned.
*/
SecretKey CryptoHelper::generateSecretKey(const NarrowString& alg, unsigned int keyBits)
{
ASSERT( !alg.empty() );
ASSERT( keyBits >= 56 );
ASSERT( (keyBits % 8) == 0 );
KeyGenerator kgen(KeyGenerator::getInstance(alg));
kgen.init(keyBits);
return kgen.generateKey();
}
示例14:
bool
V7ConfigWidget::Save(bool &_changed, bool &require_restart)
{
PopupOperationEnvironment env;
bool changed = false;
NarrowString<32> buffer;
if (SaveValue(BRGPS, brgps)) {
buffer.UnsafeFormat("%u", brgps);
device.SendV7Setting("BRGPS", buffer, env);
changed = true;
}
if (SaveValue(BRPDA, brpda)) {
buffer.UnsafeFormat("%u", brpda);
device.SendV7Setting("BRPDA", buffer, env);
changed = true;
}
_changed |= changed;
return true;
}
示例15: m_normal
AlgorithmName::AlgorithmName(const NarrowString& algorithm, bool cipherOnly)
: m_normal(normalizeAlgorithm(algorithm))
{
ASSERT( !algorithm.empty() );
// We'd prefer to throw in the ctor, but its a limitation, not a feature!
// Actually, we need to narmalize first (in case of throw), so maybe it is a feature.
NarrowString cipher;
getCipher(cipher);
if(cipherOnly && m_normal != cipher)
throw NoSuchAlgorithmException(m_normal + " not available");
}