当前位置: 首页>>代码示例>>C++>>正文


C++ encode_string函数代码示例

本文整理汇总了C++中encode_string函数的典型用法代码示例。如果您正苦于以下问题:C++ encode_string函数的具体用法?C++ encode_string怎么用?C++ encode_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了encode_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: encode_string

// Set a whitelist and/or blacklist of characters to recognize.
// An empty or NULL whitelist enables everything (minus any blacklist).
// An empty or NULL blacklist disables nothing.
// An empty or NULL blacklist has no effect.
void UNICHARSET::set_black_and_whitelist(const char* blacklist,
                                         const char* whitelist,
                                         const char* unblacklist) {
  bool def_enabled = whitelist == NULL || whitelist[0] == '\0';
  // Set everything to default
  for (int ch = 0; ch < size_used; ++ch)
    unichars[ch].properties.enabled = def_enabled;
  if (!def_enabled) {
    // Enable the whitelist.
    GenericVector<UNICHAR_ID> encoding;
    encode_string(whitelist, false, &encoding, NULL, NULL);
    for (int i = 0; i < encoding.size(); ++i) {
      if (encoding[i] != INVALID_UNICHAR_ID)
        unichars[encoding[i]].properties.enabled = true;
    }
  }
  if (blacklist != NULL && blacklist[0] != '\0') {
    // Disable the blacklist.
    GenericVector<UNICHAR_ID> encoding;
    encode_string(blacklist, false, &encoding, NULL, NULL);
    for (int i = 0; i < encoding.size(); ++i) {
      if (encoding[i] != INVALID_UNICHAR_ID)
        unichars[encoding[i]].properties.enabled = false;
    }
  }
  if (unblacklist != NULL && unblacklist[0] != '\0') {
    // Re-enable the unblacklist.
    GenericVector<UNICHAR_ID> encoding;
    encode_string(unblacklist, false, &encoding, NULL, NULL);
    for (int i = 0; i < encoding.size(); ++i) {
      if (encoding[i] != INVALID_UNICHAR_ID)
        unichars[encoding[i]].properties.enabled = true;
    }
  }
}
开发者ID:0ximDigital,项目名称:appsScanner,代码行数:39,代码来源:unicharset.cpp

示例2: encode_string_map

 size_t encode_string_map(size_t offset, const std::map<std::string, std::string>& value) {
   size_t pos = encode_uint16(offset, static_cast<uint16_t>(value.size()));
   for (std::map<std::string, std::string>::const_iterator it = value.begin();
        it != value.end(); ++it) {
     pos = encode_string(pos, it->first.c_str(), static_cast<uint16_t>(it->first.size()));
     pos = encode_string(pos, it->second.c_str(), static_cast<uint16_t>(it->second.size()));
   }
   return pos;
 }
开发者ID:cybergarage,项目名称:cpp-driver,代码行数:9,代码来源:buffer.hpp

示例3: encode_attr

void
encode_attr(DBusMessageIter *iter, int *err, const alarm_attr_t *att)
{
  encode_string(iter, err, &att->attr_name);
  encode_int   (iter, err, &att->attr_type);

  switch( att->attr_type )
  {
  case ALARM_ATTR_NULL:  break;
  case ALARM_ATTR_INT:   encode_int   (iter, err, &att->attr_data.ival); break;
  case ALARM_ATTR_TIME:  encode_time  (iter, err, &att->attr_data.tval); break;
  case ALARM_ATTR_STRING:encode_string(iter, err, &att->attr_data.sval); break;
  }
}
开发者ID:tidatida,项目名称:alarmd,代码行数:14,代码来源:codec.c

示例4: serialize_table_as_pb

int serialize_table_as_pb(lua_sandbox* lsb, int index)
{
  output_data* d = &lsb->output;
  d->pos = 0;
  size_t needed = 18;
  if (needed > d->size) {
    if (realloc_output(d, needed)) return 1;
  }

  // create a type 4 uuid
  d->data[d->pos++] = 2 | (1 << 3);
  d->data[d->pos++] = 16;
  for (int x = 0; x < 16; ++x) {
    d->data[d->pos++] = rand() % 255;
  }
  d->data[8] = (d->data[8] & 0x0F) | 0x40;
  d->data[10] = (d->data[10] & 0x0F) | 0xA0;

  // use existing or create a timestamp
  lua_getfield(lsb->lua, index, "Timestamp");
  long long ts;
  if (lua_isnumber(lsb->lua, -1)) {
    ts = (long long)lua_tonumber(lsb->lua, -1);
  } else {
    ts = (long long)(time(NULL) * 1e9);
  }
  lua_pop(lsb->lua, 1);
  if (pb_write_tag(d, 2, 0)) return 1;
  if (pb_write_varint(d, ts)) return 1;

  if (encode_string(lsb, d, 3, "Type", index)) return 1;
  if (encode_string(lsb, d, 4, "Logger", index)) return 1;
  if (encode_int(lsb, d, 5, "Severity", index)) return 1;
  if (encode_string(lsb, d, 6, "Payload", index)) return 1;
  if (encode_string(lsb, d, 7, "EnvVersion", index)) return 1;
  if (encode_int(lsb, d, 8, "Pid", index)) return 1;
  if (encode_string(lsb, d, 9, "Hostname", index)) return 1;
  if (encode_fields(lsb, d, 10, "Fields", index)) return 1;
  // if we go above 15 pb_write_tag will need to start varint encoding
  needed = 1;
  if (needed > d->size - d->pos) {
    if (realloc_output(d, needed)) return 1;
  }
  d->data[d->pos] = 0; // NULL terminate incase someone tries to treat this
                       // as a string

  return 0;
}
开发者ID:NixM0nk3y,项目名称:lua_sandbox,代码行数:48,代码来源:lua_serialize_protobuf.c

示例5: process_realpath

static void
process_realpath(u_int32_t id)
{
	char resolvedname[MAXPATHLEN];
	char *path;

	path = get_string(NULL);
	if (path[0] == '\0') {
		free(path);
		path = xstrdup(".");
	}
	debug3("request %u: realpath", id);
	verbose("realpath \"%s\"", path);
	if (realpath(path, resolvedname) == NULL) {
		send_status(id, errno_to_portable(errno));
	} else {
		Stat s;
		attrib_clear(&s.attrib);
		s.name = s.long_name = resolvedname;
		send_names(id, 1, &s);
	}

#ifdef NERSC_MOD
 	char* t1buf = encode_string(path, strlen(path));
 	s_audit("sftp_process_realpath_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), t1buf);
 	free(t1buf);
#endif

	free(path);
}
开发者ID:set-element,项目名称:DEPRICATED-InstrumentedSSHD,代码行数:31,代码来源:sftp-server.c

示例6: process_opendir

static void
process_opendir(u_int32_t id)
{
	DIR *dirp = NULL;
	char *path;
	int handle, status = SSH2_FX_FAILURE;

	path = get_string(NULL);
	debug3("request %u: opendir", id);
	logit("opendir \"%s\"", path);
	dirp = opendir(path);
	if (dirp == NULL) {
		status = errno_to_portable(errno);
	} else {
		handle = handle_new(HANDLE_DIR, path, 0, 0, dirp);
		if (handle < 0) {
			closedir(dirp);
		} else {
			send_handle(id, handle);
			status = SSH2_FX_OK;
		}

	}
	if (status != SSH2_FX_OK)
		send_status(id, status);

#ifdef NERSC_MOD
 	char* t1buf = encode_string(path, strlen(path));
 	s_audit("sftp_process_opendir_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getpid(), t1buf);
 	free(t1buf);
#endif

	free(path);
}
开发者ID:set-element,项目名称:DEPRICATED-InstrumentedSSHD,代码行数:35,代码来源:sftp-server.c

示例7: process_readdir

static void
process_readdir(u_int32_t id)
{
	DIR *dirp;
	struct dirent *dp;
	char *path;
	int handle;

	handle = get_handle();
	debug("request %u: readdir \"%s\" (handle %d)", id,
	    handle_to_name(handle), handle);
	dirp = handle_to_dir(handle);
	path = handle_to_name(handle);
	if (dirp == NULL || path == NULL) {
		send_status(id, SSH2_FX_FAILURE);
	} else {
		struct stat st;
		char pathname[MAXPATHLEN];
		Stat *stats;
		int nstats = 10, count = 0, i;

		stats = xcalloc(nstats, sizeof(Stat));
		while ((dp = readdir(dirp)) != NULL) {
			if (count >= nstats) {
				nstats *= 2;
				stats = xrealloc(stats, nstats, sizeof(Stat));
			}
/* XXX OVERFLOW ? */
			snprintf(pathname, sizeof pathname, "%s%s%s", path,
			    strcmp(path, "/") ? "/" : "", dp->d_name);
			if (lstat(pathname, &st) < 0)
				continue;
			stat_to_attrib(&st, &(stats[count].attrib));
			stats[count].name = xstrdup(dp->d_name);
			stats[count].long_name = ls_file(dp->d_name, &st, 0, 0);
			count++;
			/* send up to 100 entries in one message */
			/* XXX check packet size instead */
			if (count == 100)
				break;
		}
		if (count > 0) {
			send_names(id, count, stats);
			for (i = 0; i < count; i++) {
				free(stats[i].name);
				free(stats[i].long_name);
			}
		} else {
			send_status(id, SSH2_FX_EOF);
		}

#ifdef NERSC_MOD
 	char* t1buf = encode_string(path, strlen(path));
 	s_audit("sftp_process_readdir_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), t1buf);
#endif

		free(stats);
	}
}
开发者ID:set-element,项目名称:DEPRICATED-InstrumentedSSHD,代码行数:60,代码来源:sftp-server.c

示例8: process_mkdir

static void
process_mkdir(u_int32_t id)
{
	Attrib *a;
	char *name;
	int ret, mode, status = SSH2_FX_FAILURE;

	name = get_string(NULL);
	a = get_attrib();
	mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ?
	    a->perm & 07777 : 0777;
	debug3("request %u: mkdir", id);
	logit("mkdir name \"%s\" mode 0%o", name, mode);
	ret = mkdir(name, mode);
	status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
	send_status(id, status);

#ifdef NERSC_MOD
 	char* t1buf = encode_string(name, strlen(name));
 	s_audit("sftp_process_mkdir_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getpid(), t1buf);
 	free(t1buf);
#endif

	free(name);
}
开发者ID:set-element,项目名称:DEPRICATED-InstrumentedSSHD,代码行数:26,代码来源:sftp-server.c

示例9: process_readlink

static void
process_readlink(u_int32_t id)
{
	int len;
	char buf[MAXPATHLEN];
	char *path;

	path = get_string(NULL);
	debug3("request %u: readlink", id);
	verbose("readlink \"%s\"", path);
	if ((len = readlink(path, buf, sizeof(buf) - 1)) == -1)
		send_status(id, errno_to_portable(errno));
	else {
		Stat s;

		buf[len] = '\0';
		attrib_clear(&s.attrib);
		s.name = s.long_name = buf;
		send_names(id, 1, &s);
	}

#ifdef NERSC_MOD
        char* t1buf = encode_string( path, strlen(path));
        s_audit("sftp_process_readlink_3", "count=%i int=%d uristring=%s",
                get_client_session_id(), (int)getppid(), t1buf);
        free(t1buf);
#endif

	free(path);
}
开发者ID:set-element,项目名称:DEPRICATED-InstrumentedSSHD,代码行数:30,代码来源:sftp-server.c

示例10: process_do_stat

static void
process_do_stat(u_int32_t id, int do_lstat)
{
	Attrib a;
	struct stat st;
	char *name;
	int ret, status = SSH2_FX_FAILURE;

	name = get_string(NULL);
	debug3("request %u: %sstat", id, do_lstat ? "l" : "");
	verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
	ret = do_lstat ? lstat(name, &st) : stat(name, &st);
	if (ret < 0) {
		status = errno_to_portable(errno);
	} else {
		stat_to_attrib(&st, &a);
		send_attrib(id, &a);
		status = SSH2_FX_OK;
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);

#ifdef NERSC_MOD
 	char* t1buf = encode_string(name, strlen(name));
 	s_audit("sftp_process_do_stat_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), t1buf);
 	free(t1buf);
#endif

	free(name);
}
开发者ID:set-element,项目名称:DEPRICATED-InstrumentedSSHD,代码行数:31,代码来源:sftp-server.c

示例11: strlen

// Encodes the given UTF-8 string with this UNICHARSET.
// Returns true if the encoding succeeds completely, false if there is at
// least one INVALID_UNICHAR_ID in the returned encoding, but in this case
// the rest of the string is still encoded.
// If lengths is not NULL, then it is filled with the corresponding
// byte length of each encoded UNICHAR_ID.
bool UNICHARSET::encode_string(const char* str, bool give_up_on_failure,
                               GenericVector<UNICHAR_ID>* encoding,
                               GenericVector<char>* lengths,
                               int* encoded_length) const {
  GenericVector<UNICHAR_ID> working_encoding;
  GenericVector<char> working_lengths;
  GenericVector<char> best_lengths;
  encoding->truncate(0);  // Just in case str is empty.
  int str_length = strlen(str);
  int str_pos = 0;
  bool perfect = true;
  while (str_pos < str_length) {
    encode_string(str, str_pos, str_length, &working_encoding, &working_lengths,
                  &str_pos, encoding, &best_lengths);
    if (str_pos < str_length) {
      // This is a non-match. Skip one utf-8 character.
      perfect = false;
      if (give_up_on_failure) break;
      int step = UNICHAR::utf8_step(str + str_pos);
      if (step == 0) step = 1;
      encoding->push_back(INVALID_UNICHAR_ID);
      best_lengths.push_back(step);
      str_pos += step;
      working_encoding = *encoding;
      working_lengths = best_lengths;
    }
  }
  if (lengths != NULL) *lengths = best_lengths;
  if (encoded_length != NULL) *encoded_length = str_pos;
  return perfect;
}
开发者ID:0ximDigital,项目名称:appsScanner,代码行数:37,代码来源:unicharset.cpp

示例12: encode_string_list

 size_t encode_string_list(size_t offset, const std::vector<std::string>& value) {
   size_t pos = encode_uint16(offset, static_cast<uint16_t>(value.size()));
   for (std::vector<std::string>::const_iterator it = value.begin(),
        end = value.end(); it != end; ++it) {
     pos = encode_string(pos, it->data(), static_cast<uint16_t>(it->size()));
   }
   return pos;
 }
开发者ID:cybergarage,项目名称:cpp-driver,代码行数:8,代码来源:buffer.hpp

示例13: _T

wxString SetInfoDataObject::GetUrl() const {
	wxString url = _T("draw:/");
	url << _T("/") << m_prefix;
	url << _T("/") << m_set;

	url << _T("/");
	switch (m_period) {
		case PERIOD_T_DECADE:
			url << _T("E"); // "D is reserved for DAY"
			break;
		case PERIOD_T_YEAR:
			url << _T("Y");
			break;
		case PERIOD_T_MONTH:
			url << _T("M");
			break;
		case PERIOD_T_WEEK:
			url << _T("W");
			break;
		case PERIOD_T_SEASON:
			url << _T("S");
			break;
		case PERIOD_T_DAY:
			url << _T("D");
			break;
		case PERIOD_T_30MINUTE:
			url << _T("10M");
			break;
		case PERIOD_T_3MINUTE:
			url << _T("5M");
			break;
		case PERIOD_T_MINUTE:
			url << _T("MIN");
			break;
		default:
			assert(false);
	}

#ifndef __WXMSW__
	url << _T("/") << m_time;
#else
	url << _T("/");
	wxString tstr;
	time_t t = m_time;
	while (t) {
		int digit = t % 10;
		tstr = wxString::Format(_T("%d"), digit) + tstr;
		t /= 10;
	}
	url << tstr;
#endif
	url << _T("/") << m_selected_draw;

	return encode_string(url, true);

}
开发者ID:wds315,项目名称:szarp,代码行数:56,代码来源:drawdnd.cpp

示例14: if

// Sets the normed_ids vector from the normed string. normed_ids is not
// stored in the file, and needs to be set when the UNICHARSET is loaded.
void UNICHARSET::set_normed_ids(UNICHAR_ID unichar_id) {
  unichars[unichar_id].properties.normed_ids.truncate(0);
  if (unichar_id == UNICHAR_SPACE && id_to_unichar(unichar_id)[0] == ' ') {
    unichars[unichar_id].properties.normed_ids.push_back(UNICHAR_SPACE);
  } else if (!encode_string(unichars[unichar_id].properties.normed.string(),
                            true, &unichars[unichar_id].properties.normed_ids,
                            NULL, NULL)) {
    unichars[unichar_id].properties.normed_ids.truncate(0);
    unichars[unichar_id].properties.normed_ids.push_back(unichar_id);
  }
}
开发者ID:bhanu475,项目名称:tesseract,代码行数:13,代码来源:unicharset.cpp

示例15: GetStrProperties

// Gets the properties for a grapheme string, combining properties for
// multiple characters in a meaningful way where possible.
// Returns false if no valid match was found in the unicharset.
// NOTE that script_id, mirror, and other_case refer to this unicharset on
// return and will need translation if the target unicharset is different.
bool UNICHARSET::GetStrProperties(const char* utf8_str,
                                  UNICHAR_PROPERTIES* props) const {
  props->Init();
  props->SetRangesEmpty();
  int total_unicodes = 0;
  GenericVector<UNICHAR_ID> encoding;
  if (!encode_string(utf8_str, true, &encoding, NULL, NULL))
    return false;  // Some part was invalid.
  for (int i = 0; i < encoding.size(); ++i) {
    int id = encoding[i];
    const UNICHAR_PROPERTIES& src_props = unichars[id].properties;
    // Logical OR all the bools.
    if (src_props.isalpha) props->isalpha = true;
    if (src_props.islower) props->islower = true;
    if (src_props.isupper) props->isupper = true;
    if (src_props.isdigit) props->isdigit = true;
    if (src_props.ispunctuation) props->ispunctuation = true;
    if (src_props.isngram) props->isngram = true;
    if (src_props.enabled) props->enabled = true;
    // Min/max the tops/bottoms.
    UpdateRange(src_props.min_bottom, &props->min_bottom, &props->max_bottom);
    UpdateRange(src_props.max_bottom, &props->min_bottom, &props->max_bottom);
    UpdateRange(src_props.min_top, &props->min_top, &props->max_top);
    UpdateRange(src_props.max_top, &props->min_top, &props->max_top);
    float bearing = props->advance + src_props.bearing;
    if (total_unicodes == 0 || bearing < props->bearing) {
      props->bearing = bearing;
      props->bearing_sd = props->advance_sd + src_props.bearing_sd;
    }
    props->advance += src_props.advance;
    props->advance_sd += src_props.advance_sd;
    // With a single width, just use the widths stored in the unicharset.
    props->width = src_props.width;
    props->width_sd = src_props.width_sd;
    // Use the first script id, other_case, mirror, direction.
    // Note that these will need translation, except direction.
    if (total_unicodes == 0) {
      props->script_id = src_props.script_id;
      props->other_case = src_props.other_case;
      props->mirror = src_props.mirror;
      props->direction = src_props.direction;
    }
    // The normed string for the compound character is the concatenation of
    // the normed versions of the individual characters.
    props->normed += src_props.normed;
    ++total_unicodes;
  }
  if (total_unicodes > 1) {
    // Estimate the total widths from the advance - bearing.
    props->width = props->advance - props->bearing;
    props->width_sd = props->advance_sd + props->bearing_sd;
  }
  return total_unicodes > 0;
}
开发者ID:bhanu475,项目名称:tesseract,代码行数:59,代码来源:unicharset.cpp


注:本文中的encode_string函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。