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


C++ MyString::Length方法代码示例

本文整理汇总了C++中MyString::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ MyString::Length方法的具体用法?C++ MyString::Length怎么用?C++ MyString::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyString的用法示例。


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

示例1: strnewp

//---------------------------------------------------------------------------
const char *
Job::GetJobstateJobTag()
{
	if ( !_jobTag ) {
		MyString jobTagName = MultiLogFiles::loadValueFromSubFile(
					_cmdFile, _directory, JOB_TAG_NAME );
		if ( jobTagName == "" ) {
			jobTagName = PEGASUS_SITE;
		} else {
				// Remove double-quotes
			int begin = jobTagName[0] == '\"' ? 1 : 0;
			int last = jobTagName.Length() - 1;
			int end = jobTagName[last] == '\"' ? last - 1 : last;
			jobTagName = jobTagName.Substr( begin, end );
		}

		MyString tmpJobTag = MultiLogFiles::loadValueFromSubFile(
					_cmdFile, _directory, jobTagName.Value() );
		if ( tmpJobTag == "" ) {
			tmpJobTag = "-";
		} else {
				// Remove double-quotes
			int begin = tmpJobTag[0] == '\"' ? 1 : 0;
			int last = tmpJobTag.Length() - 1;
			int end = tmpJobTag[last] == '\"' ? last - 1 : last;
			tmpJobTag = tmpJobTag.Substr( begin, end );
		}
		_jobTag = strnewp( tmpJobTag.Value() );
	}

	return _jobTag;
}
开发者ID:Clusterforge,项目名称:htcondor,代码行数:33,代码来源:job.cpp

示例2: cleanStringForUseAsAttr

// Remove/replace characters from the string so it can be used as an attribute name
// it changes the string that is passed to it.  first leading an trailing spaces
// are removed, then Characters that are invalid in compatible classads 
// (basically anthing but [a-zA-Z0-9_]) is replaced with chReplace.
// if chReplace is 0, then invalid characters are removed. 
// if compact is true, then multiple consecutive runs of chReplace
// are changed to a single instance.
// return value is the length of the resulting string.
//
int cleanStringForUseAsAttr(MyString &str, char chReplace/*=0*/, bool compact/*=true*/)
{
   // have 0 mean 'remove' since we can't actually use it as a replacement char
   // we'll actually implement it by replacing invalid chars with spaces,
   // and then compacting to remove all of the spaces.
   if (0 == chReplace) {
      chReplace = ' ';
      compact = true;
   }

   // trim the input and replace invalid chars with chReplace
   str.trim();
   for (int ii = 0; ii < str.Length(); ++ii) {
      char ch = str[ii];
      if (ch == '_' || (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
         continue;
      str.setChar(ii,chReplace);
      }

   // if compact, convert runs of chReplace with a single instance,
   // unless chReplace is ' ', then remove them entirely.
   if (compact) {
      if (chReplace == ' ')
         str.replaceString(" ","");
      else {
         MyString tmp; tmp += chReplace; tmp += chReplace;
         str.replaceString(tmp.Value(), tmp.Value()+1);
      }
   }
   str.trim();
   return str.Length();
}
开发者ID:AmesianX,项目名称:htcondor,代码行数:41,代码来源:classad_helpers.cpp

示例3: toReturn

// +, += (concatenation - takes a MyString or a c style string)
MyString MyString::operator+ (const MyString & aMyString)
{
	// Get the total length of the two strings and create a MyString to return
	int totalLen = this->Length() + aMyString.Length();
	MyString toReturn(totalLen + 1);

	// Ensure that the MyString has a length
	toReturn._length = totalLen;

	// Add the null character
	toReturn._string[totalLen] = '\0';

	// The current position in relativity to the total
	int currentPos = 0;
    
	// Take the values from this
	for (int i = 0; i < this->Length(); i++)
	{
		toReturn._string[currentPos] = this->_string[i];
		currentPos++;
	}

	// Take the values from aMyString
	for (int i = 0; i < aMyString.Length(); i++)
	{
		toReturn[currentPos] = aMyString[i];
		currentPos++;
	}

	return toReturn;
}
开发者ID:unseenshadow2,项目名称:UAT-Cpp2-Project-2,代码行数:32,代码来源:MyString.cpp

示例4:

void
MapFile::PerformSubstitution(ExtArray<MyString> & groups,
							 const MyString pattern,
							 MyString & output)
{
	for (int index = 0; index < pattern.Length(); index++) {
		if ('\\' == pattern[index]) {
			index++;
			if (index < pattern.Length()) {
				if ('1' <= pattern[index] &&
					'9' >= pattern[index]) {
					int match = pattern[index] - '0';
					if (groups.getlast() >= match) {
						output += groups[match];
						continue;
					}
				}

				output += '\\';
			}
		}

		output += pattern[index];
	}
}
开发者ID:AlainRoy,项目名称:htcondor,代码行数:25,代码来源:MapFile.cpp

示例5: serialize

void
AvailStats::checkpoint()
{
		// Checkpoint our state to disk by serializing to a string
		// and writing the string to disk.  It's not very efficient
		// to create this string each time, but it shouldn't be too big
		// (under 1KB), so I don't think it's worth worrying too much
		// about efficiency.
	if( ckpt_filename.Length() ) {
		FILE *fp = safe_fopen_wrapper_follow(tmp_ckpt_filename.Value(), "w");
		if( fp ) {
			MyString state = serialize();
			if( (int)fwrite(state.Value(), sizeof(char), state.Length(),
							fp) == state.Length() ) {
				fclose(fp);
				if ( rotate_file(tmp_ckpt_filename.Value(),
								 ckpt_filename.Value()) < 0 ) {
					dprintf( D_ALWAYS,
							 "AvailStats::checkpoint() failed to rotate "
							 "%s to %s\n",
							 tmp_ckpt_filename.Value(),
							 ckpt_filename.Value() );
				}
			} else {
				fclose(fp);
			}
		}
	}
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例6: append_arg

void append_arg(char const *arg,MyString &result) {
	if(result.Length()) {
		result += " ";
	}
	ASSERT(arg);
	if(!*arg) {
		result += "''"; //empty arg
	}
	while(*arg) {
		switch(*arg) {
		case ' ':
		case '\t':
		case '\n':
		case '\r':
		case '\'':
			if(result.Length() && result[result.Length()-1] == '\'') {
				//combine preceeding quoted section with this one,
				//so we do not introduce a repeated quote.
				result.setChar(result.Length()-1,'\0');
			}
			else {
				result += '\'';
			}
			if(*arg == '\'') {
				result += '\''; //repeat the quote to escape it
			}
			result += *(arg++);
			result += '\'';
			break;
		default:
			result += *(arg++);
		}
	}
}
开发者ID:,项目名称:,代码行数:34,代码来源:

示例7: strArg

int  
parseMyProxyArgument (const char * arg,
					  char * & user, 
					  char * & host, 
					  int & port) {

	MyString strArg (arg);
	int at_idx = strArg.FindChar ((int)'@');
	int colon_idx = strArg.FindChar ((int)':', at_idx+1);

	if (at_idx != -1) {
		MyString _user = strArg.Substr (0, at_idx-1);
		user = strdup(_user.Value());
	}
  
  
	if (colon_idx == -1) {
		MyString _host = strArg.Substr (at_idx+1, strArg.Length()-1);
		host = strdup(_host.Value());
	} else {
		MyString _host = strArg.Substr (at_idx+1, colon_idx-1);
		host = strdup(_host.Value());

		MyString _port = strArg.Substr (colon_idx+1, strArg.Length()-1);
		port = atoi(_port.Value());

	}

	return TRUE;
}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例8: convert_hostname_to_ipaddr

condor_sockaddr convert_hostname_to_ipaddr(const MyString& fullname)
{
	MyString hostname;
	MyString default_domain;
	bool truncated = false;
	if (param(default_domain, "DEFAULT_DOMAIN_NAME")) {
		MyString dotted_domain = ".";
		dotted_domain += default_domain;
		int pos = fullname.find(dotted_domain.Value());
		if (pos != -1) {
			truncated = true;
			hostname = fullname.Substr(0, pos - 1);
		}
	}
	if (!truncated)
		hostname = fullname;

	// detects if hostname is IPv6
	//
	// hostname is NODNS coded address
	//
	// for example,
	// it could be 127-0-0-1 (127.0.0.1) as IPv4 address
	// it could be fe80-3577--1234 ( fe80:3577::1234) as IPv6 address
	//
	// it is IPv6 address
	// 1) if there are 7 '-'
	// 2) if there are '--' which means compaction of zeroes in IPv6 adress

	char target_char;
	bool ipv6 = false;
	if (hostname.find("--") != -1)
		ipv6 = true;
	else {
		int dash_count = 0;
		for (int i = 0; i < hostname.Length(); ++i)
			if (hostname[i] == '-')
				++dash_count;

		if (dash_count == 7)
			ipv6 = true;
	}

	if (ipv6)
		target_char = ':';
	else
		target_char ='.';
		// converts hostname to IP address string
	for (int i = 0; i < hostname.Length(); ++i) {
		if (hostname[i] == '-')
			hostname.setChar(i, target_char);
	}

	condor_sockaddr ret;
	ret.from_ip_string(hostname);
	return ret;
}
开发者ID:AlainRoy,项目名称:htcondor,代码行数:57,代码来源:ipv6_hostname.cpp

示例9: dup

int
main(int, char* argv[])
{
	MyString err;

	// dup FD 0 since well will later replace FD 0 with the job's stdin
	//
	int sock_fd = dup(0);
	if (sock_fd == -1) {
		err.sprintf("dup error on FD 0: %s", strerror(errno));
		full_write(0, err.Value(), err.Length() + 1);
		exit(1);
	}

	// set up an Env object that we'll use for the job. we'll initialize
	// it with the environment that Condor sends us then merge on top of
	// that the environment that glexec prepared for us
	//
	Env env;
	char* env_buf = read_env(sock_fd);
	MyString merge_err;
	if (!env.MergeFromV2Raw(env_buf, &merge_err)) {
		err.sprintf("Env::MergeFromV2Raw error: %s", merge_err.Value());
		full_write(sock_fd, err.Value(), err.Length() + 1);
		exit(1);
	}
	env.MergeFrom(environ);
	delete[] env_buf;

	// now receive an FD on our stdin (which is a UNIX domain socket)
	// that we'll use as the job's stdin
	//
	int job_fd = read_fd(sock_fd);
	if (dup2(job_fd, 0) == -1) {
		err.sprintf("dup2 to FD 0 error: %s", strerror(errno));
		full_write(sock_fd, err.Value(), err.Length() + 1);
		exit(1);
	}
	close(job_fd);
	if (fcntl(sock_fd, F_SETFD, FD_CLOEXEC) == -1) {
		err.sprintf("fcntl error setting close-on-exec: %s",
		            strerror(errno));
		full_write(sock_fd, err.Value(), err.Length() + 1);
		exit(1);
	}

	// now we can exec the job. for arguments, we shift this wrappers
	// arguments by one. similarly, the job's executable path is taken
	// as our argv[1]
	//
	char** envp = env.getStringArray();
	execve(argv[1], &argv[1], envp);
	err.sprintf("execve error: %s", strerror(errno));
	full_write(sock_fd, err.Value(), err.Length() + 1);
	exit(1);
}
开发者ID:,项目名称:,代码行数:56,代码来源:

示例10: findPrevDelimiter

// Given an offset count that points to a delimiter, this function returns the 
// previous delimiter offset position.
// If clusterId and procId is specified, it will not return the immediately
// previous delimiter, but the nearest previous delimiter that matches
static long findPrevDelimiter(FILE *fd, char* filename, long currOffset)
{
    MyString buf;
    char *owner;
    long prevOffset = -1, completionDate = -1;
    int clusterId = -1, procId = -1;
  
    fseek(fd, currOffset, SEEK_SET);
    buf.readLine(fd);
  
    owner = (char *) malloc(buf.Length() * sizeof(char)); 

    // Current format of the delimiter:
    // *** ProcId = a ClusterId = b Owner = "cde" CompletionDate = f
    // For the moment, owner and completionDate are just parsed in, reserved for future functionalities. 

    sscanf(buf.Value(), "%*s %*s %*s %ld %*s %*s %d %*s %*s %d %*s %*s %s %*s %*s %ld", 
           &prevOffset, &clusterId, &procId, owner, &completionDate);

    if (prevOffset == -1 && clusterId == -1 && procId == -1) {
        fprintf(stderr, 
                "Error: (%s) is an incompatible history file, please run condor_convert_history.\n",
                filename);
        free(owner);
        exit(1);
    }

    // If clusterId.procId is specified
    if (cluster != -1 || proc != -1) {

        // Ok if only clusterId specified
        while (clusterId != cluster || (proc != -1 && procId != proc)) {
	  
            if (prevOffset == 0) { // no match
                free(owner);
                return -1;
            }

            // Find previous delimiter + summary
            fseek(fd, prevOffset, SEEK_SET);
            buf.readLine(fd);
            
            owner = (char *) realloc (owner, buf.Length() * sizeof(char));
      
            sscanf(buf.Value(), "%*s %*s %*s %ld %*s %*s %d %*s %*s %d %*s %*s %s %*s %*s %ld", 
                   &prevOffset, &clusterId, &procId, owner, &completionDate);
        }
    }
 
    free(owner);
		 
    return prevOffset;
} 
开发者ID:emaste,项目名称:htcondor,代码行数:57,代码来源:dump_history.cpp

示例11: getWritePassword

//! Gets the writer password required by the quill++
//  daemon to access the database
static MyString getWritePassword(const char *write_passwd_fname, 
							   const char *host, const char *port, 
							   const char *db,
							   const char *dbuser) {
	FILE *fp = NULL;
	MyString passwd;
	int len;
	MyString prefix;
	MyString msbuf;
	const char *buf;
	bool found = FALSE;

		// prefix is for the prefix of the entry in the .pgpass
		// it is in the format of the following:
		// host:port:db:user:password

	prefix.sprintf("%s:%s:%s:%s:", host, port, db, dbuser);

	len = prefix.Length();

	fp = safe_fopen_wrapper(write_passwd_fname, "r");

	if(fp == NULL) {
		EXCEPT("Unable to open password file %s\n", write_passwd_fname);
	}
	
		//dprintf(D_ALWAYS, "prefix: %s\n", prefix);

	while(msbuf.readLine(fp)) {
		msbuf.chomp();
		buf = msbuf.Value();

			//fprintf(stderr, "line: %s\n", buf);

			// check if the entry matches the prefix
		if (strncmp(buf, prefix.Value(), len) == 0) {
				// extract the password
			passwd = msbuf.Substr(len, msbuf.Length());
			found = TRUE;

			break;
		}

	}

    fclose(fp);
	if (!found) {
		EXCEPT("Unable to find password from file %s\n", write_passwd_fname);
	}

	return passwd;
}
开发者ID:,项目名称:,代码行数:54,代码来源:

示例12:

CheckEvents::check_event_result_t
CheckEvents::CheckAllJobs(MyString &errorMsg)
{
	check_event_result_t	result = EVENT_OKAY;
	errorMsg = "";

	const int	MAX_MSG_LEN = 1024;
	bool		msgFull = false; // message length has hit max

	CondorID	id;
	JobInfo *info = NULL;
	jobHash.startIterations();
	while ( jobHash.iterate(id, info) != 0 ) {

			// Put a limit on the maximum message length so we don't
			// have a chance of ending up with a ridiculously large
			// MyString...
		if ( !msgFull && (errorMsg.Length() > MAX_MSG_LEN) ) {
			errorMsg += " ...";
			msgFull = true;
		}

		MyString	idStr("BAD EVENT: job ");
		idStr.formatstr_cat("(%d.%d.%d)", id._cluster, id._proc, id._subproc);

		MyString	tmpMsg;
		CheckJobFinal(idStr, id, info, tmpMsg, result);
		if ( tmpMsg != "" && !msgFull ) {
			if ( errorMsg != "" ) errorMsg += "; ";
			errorMsg += tmpMsg;
		}
	}

	return result;
}
开发者ID:AlainRoy,项目名称:htcondor,代码行数:35,代码来源:check_events.cpp

示例13: Insert

      // Insert
            // Takes two arguments
            // An int – the index in this MyString
//   at which to insert the new chars
            // A MyString containing the chars to be inserted
void MyString::Insert(const MyString & aMyString, int index)
{
	int lengthOfAMyString = aMyString.Length();
	int newCapacity = _length + lengthOfAMyString;
	_capacity = newCapacity;

	char *tempStr = new char[_capacity + 1];

	for(int i = 0; i < index; i++)
	{
		tempStr[i] = _string[i];
	}
	tempStr[index] = '\0';

	strcat(tempStr, aMyString._cstr());

	for(int i = 0; i <= _length - index; i++)
	{
		tempStr[index + lengthOfAMyString + i] = _string[index + i];
	}

	_length = _capacity;
	delete [] _string;
	_string = tempStr;
}
开发者ID:Reline,项目名称:AppointmentManager,代码行数:30,代码来源:MyString.cpp

示例14:

bool
privsep_get_switchboard_response(FILE* err_fp, MyString *response)
{
	// first read everything off the error pipe and close
	// the error pipe
	//
	MyString err;
	while (err.readLine(err_fp, true)) { }
	fclose(err_fp);
	
	// if this is passed in, assume the caller will handle any
	// error propagation, and we just succeed.
	if (response) {
		*response = err;
		return true;
	}

	// if there was something there, print it out here (since no one captured
	// the error message) and return false to indicate something went wrong.
	if (err.Length() != 0) {
		dprintf(D_ALWAYS,
		        "privsep_get_switchboard_response: error received: %s",
			err.Value());
		return false;
	}

	// otherwise, indicate that everything's fine
	//
	return true;
}
开发者ID:AlainRoy,项目名称:htcondor,代码行数:30,代码来源:privsep_client.UNIX.cpp

示例15: Replace

// Replace
// Takes three arguments
// An int – the index of the char in thisMyString
//   to begin replacing at.
// An int – the number of chars to replace
// And a MyString containg the replacement string
// throws an exception if startIndex >= Length
// throws an exception if startIndex + numChars > Length()
// throws an exception if aMyString.Length() < numChars
void MyString::Replace(int startIndex, int numChars, const MyString & aMyString)
{
	// Exception check
	if (startIndex >= this->Length())
	{
		throw "!Access Violation!";
	}
	// Exception check
	if (startIndex + numChars > this->Length())
	{
		throw "!Access Violation!";
	}
	// Exception check
	if (aMyString.Length() < numChars)
	{
		throw "!Access Violation!";
	}

	//for loop for index of this string
	for (int i = startIndex; i < startIndex + numChars; i++)
	{
		//for loop for proper index of aMyString
		for (int j = 0; j < numChars; j++)
		{
			this->_string[i] = aMyString[j];
		}
	}
}
开发者ID:unseenshadow2,项目名称:UAT-Cpp2-Project-2,代码行数:37,代码来源:MyString.cpp


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