本文整理汇总了C++中CStrRef::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ CStrRef::c_str方法的具体用法?C++ CStrRef::c_str怎么用?C++ CStrRef::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStrRef
的用法示例。
在下文中一共展示了CStrRef::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: t_getstats
Array c_Memcache::t_getstats(CStrRef type /* = null_string */,
int slabid /* = 0 */, int limit /* = 100 */) {
if (!memcached_server_count(&m_memcache)) {
return NULL;
}
char extra_args[30] = {0};
if (slabid) {
snprintf(extra_args, sizeof(extra_args), "%s %d %d", type.c_str(),
slabid, limit);
} else if (!type.empty()) {
snprintf(extra_args, sizeof(extra_args), "%s", type.c_str());
}
memcached_server_instance_st instance =
memcached_server_instance_by_position(&m_memcache, 0);
memcached_stat_st stats;
if (memcached_stat_servername(&stats, extra_args, instance->hostname,
instance->port) != MEMCACHED_SUCCESS) {
return NULL;
}
memcached_return_t ret;
return memcache_build_stats(&m_memcache, &stats, &ret);
}
示例2: f_get_class_vars
Array f_get_class_vars(CStrRef class_name) {
ClassInfo::PropertyVec properties;
ClassInfo::GetClassProperties(properties, class_name);
CStrRef context = FrameInjection::GetClassName(true);
const ClassInfo *cls = NULL;
if (!context.empty()) {
cls = ClassInfo::FindClass(context);
}
Array ret = Array::Create();
// PHP has instance variables appear before static variables...
for (unsigned int i = 0; i < properties.size(); i++) {
if (!(properties[i]->attribute & ClassInfo::IsStatic) &&
properties[i]->isVisible(cls)) {
ret.set(properties[i]->name,
get_class_var_init(class_name.c_str(), properties[i]->name));
}
}
for (unsigned int i = 0; i < properties.size(); i++) {
if (properties[i]->attribute & ClassInfo::IsStatic &&
properties[i]->isVisible(cls)) {
ret.set(properties[i]->name,
get_static_property(class_name.c_str(), properties[i]->name));
}
}
return ret;
}
示例3: writeSerializedProperty
void VariableSerializer::writeSerializedProperty(CStrRef prop,
const ClassInfo *cls) {
String res = prop;
const ClassInfo *origCls = cls;
if (cls) {
ClassInfo::PropertyInfo *p = cls->getPropertyInfo(prop.c_str());
// Try to find defining class
while (!p && cls && cls->getParentClass()) {
cls = ClassInfo::FindClass(cls->getParentClass());
if (cls) p = cls->getPropertyInfo(prop);
}
if (p) {
const ClassInfo *dcls = p->owner;
ClassInfo::Attribute a = p->attribute;
if (a & ClassInfo::IsProtected) {
res = String("\0*\0", 3, AttachLiteral) + prop;
} else if (a & ClassInfo::IsPrivate && cls == origCls) {
const char *clsname = dcls->getName();
int clsLen = strlen(clsname);
int headerLen = clsLen + 2;
int totalLen = headerLen + prop.size() + 1;
char *buf = (char*)malloc(totalLen);
buf[0] = '\0';
memcpy(buf + 1, clsname, clsLen);
buf[clsLen + 1] = '\0';
memcpy(buf + headerLen, prop.c_str(), prop.size());
buf[totalLen - 1] = '\0';
res = String(buf, totalLen - 1, AttachString);
}
}
}
write(res);
}
示例4: f_socket_sendto
Variant f_socket_sendto(CObjRef socket, CStrRef buf, int len, int flags,
CStrRef addr, int port /* = 0 */) {
Socket *sock = socket.getTyped<Socket>();
if (len > buf.size()) {
len = buf.size();
}
int retval;
switch (sock->getType()) {
case AF_UNIX:
{
struct sockaddr_un s_un;
memset(&s_un, 0, sizeof(s_un));
s_un.sun_family = AF_UNIX;
snprintf(s_un.sun_path, 108, "%s", addr.data());
retval = sendto(sock->fd(), buf.data(), len, flags,
(struct sockaddr *)&s_un, SUN_LEN(&s_un));
}
break;
case AF_INET:
{
struct sockaddr_in sin;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons((unsigned short) port);
if (!php_set_inet_addr(&sin, addr.c_str(), sock)) {
return false;
}
retval = sendto(sock->fd(), buf.data(), len, flags,
(struct sockaddr *)&sin, sizeof(sin));
}
break;
case AF_INET6:
{
struct sockaddr_in6 sin6;
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
sin6.sin6_port = htons((unsigned short) port);
if (!php_set_inet6_addr(&sin6, addr.c_str(), sock)) {
return false;
}
retval = sendto(sock->fd(), buf.data(), len, flags,
(struct sockaddr *)&sin6, sizeof(sin6));
}
break;
default:
raise_warning("Unsupported socket type %d", sock->getType());
return false;
}
if (retval == -1) {
SOCKET_ERROR(sock, "unable to write to socket", errno);
return false;
}
return retval;
}
示例5: moveUploadedFile
bool Transport::moveUploadedFile(CStrRef filename, CStrRef destination) {
if (!is_uploaded_file(filename.c_str())) {
Logger::Error("%s is not an uploaded file.", filename.c_str());
return false;
}
return moveUploadedFileHelper(filename, destination);
}
示例6: t_setallowedlocales
void c_SpoofChecker::t_setallowedlocales(CStrRef localesList) {
UErrorCode status = U_ZERO_ERROR;
uspoof_setAllowedLocales(
m_spoof_checker,
localesList.c_str(),
&status);
if (U_FAILURE(status)) {
throw Exception(
"Could not set allowed locales to [%s], error %d (%s)",
localesList.c_str(), status, u_errorName(status));
}
}
示例7: getenv
String BaseExecutionContext::getenv(CStrRef name) const {
if (m_envs.exists(name)) {
return m_envs[name];
}
char *value = ::getenv(name.data());
if (value) {
return String(value, CopyString);
}
if (RuntimeOption::EnvVariables.find(name.c_str()) != RuntimeOption::EnvVariables.end()) {
return String(RuntimeOption::EnvVariables[name.c_str()].data(), CopyString);
}
return String();
}
示例8: t_connect
bool c_Memcache::t_connect(CStrRef host, int port /*= 0*/,
int timeout /*= 0*/,
int timeoutms /*= 0*/) {
memcached_return_t ret;
if (!host.empty() && host[0] == '/') {
ret = memcached_server_add_unix_socket(&m_memcache, host.c_str());
} else {
ret = memcached_server_add(&m_memcache, host.c_str(), port);
}
return (ret == MEMCACHED_SUCCESS);
}
示例9: moveUploadedFileHelper
// Move a file if and only if it was created by an upload
bool Transport::moveUploadedFileHelper(CStrRef filename, CStrRef destination) {
// Do access check.
String dest = File::TranslatePath(destination);
if (Util::rename(filename.c_str(), dest.c_str()) < 0) {
Logger::Error("Unable to move uploaded file %s to %s: %s.",
filename.c_str(), dest.c_str(),
Util::safe_strerror(errno).c_str());
return false;
}
Logger::Verbose("Successfully moved uploaded file %s to %s.",
filename.c_str(), dest.c_str());
return true;
}
示例10: open
bool UrlFile::open(CStrRef url, CStrRef mode) {
const char* modestr = mode.c_str();
if (strchr(modestr, '+') || strchr(modestr, 'a') || strchr(modestr, 'w')) {
std::string msg = "cannot open a url stream for write/append operation: ";
msg += url.c_str();
m_error = msg;
return false;
}
HttpClient http(m_timeout, m_maxRedirect);
m_response.reset();
HeaderMap *pHeaders = nullptr;
HeaderMap requestHeaders;
if (!m_headers.empty()) {
pHeaders = &requestHeaders;
for (ArrayIter iter(m_headers); iter; ++iter) {
requestHeaders[string(iter.first().toString().data())].
push_back(iter.second().toString().data());
}
}
int code;
vector<String> responseHeaders;
if (m_get) {
code = http.get(url.c_str(), m_response, pHeaders, &responseHeaders);
} else {
code = http.post(url.c_str(), m_postData.data(), m_postData.size(),
m_response, pHeaders, &responseHeaders);
}
SystemGlobals *g = (SystemGlobals*)get_global_variables();
Variant &r = g->GV(http_response_header);
r = Array::Create();
for (unsigned int i = 0; i < responseHeaders.size(); i++) {
r.append(responseHeaders[i]);
}
m_responseHeaders = r;
if (code == 200) {
m_name = (std::string) url;
m_data = const_cast<char*>(m_response.data());
m_len = m_response.size();
return true;
} else {
m_error = http.getLastError().c_str();
return false;
}
}
示例11: f_system
String f_system(CStrRef command, VRefParam return_var /* = null */) {
ShellExecContext ctx;
FILE *fp = ctx.exec(command.c_str());
if (!fp) return "";
StringBuffer sbuf;
if (fp) {
sbuf.read(fp);
}
Array lines = StringUtil::Explode(sbuf.detach(), "\n");
int ret = ctx.exit();
if (WIFEXITED(ret)) ret = WEXITSTATUS(ret);
return_var = ret;
int count = lines.size();
if (count > 0 && lines[count - 1].toString().empty()) {
count--; // remove explode()'s last empty line
}
for (int i = 0; i < count; i++) {
echo(lines[i]);
echo("\n");
}
if (!count || lines.empty()) {
return String();
}
return StringUtil::Trim(lines[count - 1], StringUtil::TrimRight);
}
示例12: f_bzcompress
Variant f_bzcompress(CStrRef source, int blocksize /* = 4 */,
int workfactor /* = 0 */) {
char *dest = NULL;
int error;
unsigned int source_len, dest_len;
source_len = source.length();
dest_len = source.length() + (0.01*source.length()) + 600;
if (!(dest = (char *)malloc(dest_len + 1))) {
return BZ_MEM_ERROR;
}
error = BZ2_bzBuffToBuffCompress(dest, &dest_len, (char *) source.c_str(),
source_len, blocksize, 0, workfactor);
if (error != BZ_OK) {
free(dest);
return error;
} else {
// this is to shrink the allocation, since we probably over allocated
dest = (char *)realloc(dest, dest_len + 1);
dest[dest_len] = '\0';
String ret = String(dest, dest_len, AttachString);
return ret;
}
}
示例13: getMultiImpl
bool c_Memcached::getMultiImpl(CStrRef server_key, CArrRef keys,
bool enableCas, Array *returnValue) {
vector<const char*> keysCopy;
keysCopy.reserve(keys.size());
vector<size_t> keysLengthCopy;
keysLengthCopy.reserve(keys.size());
for (ArrayIter iter(keys); iter; ++iter) {
Variant vKey = iter.second();
if (!vKey.isString()) continue;
StringData *key = vKey.getStringData();
if (key->empty()) continue;
keysCopy.push_back(key->data());
keysLengthCopy.push_back(key->size());
if (returnValue) returnValue->set(String(key), null_variant, true);
}
if (keysCopy.size() == 0) {
m_impl->rescode = q_Memcached_RES_BAD_KEY_PROVIDED;
return false;
}
memcached_behavior_set(&m_impl->memcached, MEMCACHED_BEHAVIOR_SUPPORT_CAS,
enableCas ? 1 : 0);
const char *myServerKey = server_key.empty() ? NULL : server_key.c_str();
size_t myServerKeyLen = server_key.length();
return handleError(memcached_mget_by_key(&m_impl->memcached,
myServerKey, myServerKeyLen, keysCopy.data(), keysLengthCopy.data(),
keysCopy.size()));
}
示例14: f_exec
String f_exec(CStrRef command, VRefParam output /* = null */,
VRefParam return_var /* = null */) {
ShellExecContext ctx;
FILE *fp = ctx.exec(command.c_str());
if (!fp) return "";
StringBuffer sbuf;
sbuf.read(fp);
Array lines = StringUtil::Explode(sbuf.detach(), "\n");
int ret = ctx.exit();
if (WIFEXITED(ret)) ret = WEXITSTATUS(ret);
return_var = ret;
int count = lines.size();
if (count > 0 && lines[count - 1].toString().empty()) {
count--; // remove explode()'s last empty line
}
if (!output.is(KindOfArray)) {
output = Array(ArrayData::Create());
}
for (int i = 0; i < count; i++) {
output.append(lines[i]);
}
if (!count || lines.empty()) {
return String();
}
return StringUtil::Trim(lines[count - 1], StringUtil::TrimRight);
}
示例15: splitHeader
bool Transport::splitHeader(CStrRef header, String &name, const char *&value) {
int pos = header.find(':');
if (pos != String::npos) {
name = header.substr(0, pos);
value = header.data() + pos;
do {
value++;
} while (*value == ' ');
return true;
}
// header("HTTP/1.0 404 Not Found");
// header("HTTP/1.0 404");
if (strncasecmp(header.data(), "http/", 5) == 0) {
int pos1 = header.find(' ');
if (pos1 != String::npos) {
int pos2 = header.find(' ', pos1 + 1);
if (pos2 == String::npos) pos2 = header.size();
if (pos2 - pos1 > 1) {
setResponse(atoi(header.data() + pos1),
getResponseInfo().empty() ? "splitHeader"
: getResponseInfo().c_str()
);
return false;
}
}
}
throw InvalidArgumentException("header", header.c_str());
}