Example #1
0
// -----------------------------------------------------------------------------
// CATBase::GetEpocRoot( string& sEpocRoot )
// -----------------------------------------------------------------------------
bool CATBase::GetEpocRoot( string& sEpocRoot )
{
	LOG_FUNC_ENTRY( "CATBase::GetEpocRoot" );
	bool bRet = true;
	//Find EPOCROOT from environment variable
	char* pEpocRoot = getenv ("EPOCROOT");
	if( pEpocRoot == NULL )
	{
		const char pDevicesPath[] = "C:\\Program Files\\Common Files\\Symbian\\devices.xml";
		CATParseXML parser;
		//Find EPOCROOT from devices
		sEpocRoot = parser.GetEpocRootPathFromXML(pDevicesPath);
		if( sEpocRoot.empty() )
		{
			printf("EPOCROOT not set to environment variables.\n");
			bRet = false;
		}
	}
	else
	{
		sEpocRoot.append( pEpocRoot );
		LOG_STRING( "EpocRoot :" << sEpocRoot );
	}
	//Remove trailing slash
	if ( sEpocRoot.size() > 1 && sEpocRoot[ sEpocRoot.length()-1 ] == '\\' )
		sEpocRoot.resize( sEpocRoot.length()-1 );
	return bRet;
}
Example #2
0
unsigned int FSManager::saveFATRecord(string fileName, unsigned int fileBlock, unsigned long fileSize)
{
    Block FATBlock;
    unsigned int fatBlock = findFatBlock();
    if (!fatBlock)
        return -1;
    diskFile.seekg((fatBlock - 1) * blkSize + sizeof (DiskInfo));
    diskFile.read((char*) & FATBlock, sizeof (FATBlock));
    if (FATBlock.checker != 123)
    {
        cout << "Blad w saveFATRecord! checker\n";
        exit(1);
    }
    diskFile.seekp(blkSize * (fatBlock - 1) + sizeof (FATBlock) + FATBlock.size + sizeof (DiskInfo));
    FileInfo fInfo;
    if (fileName.size() > 63)
        fileName.resize(63);
    strcpy(fInfo.fileName, fileName.c_str());
    fInfo.startBlock = fileBlock;
    fInfo.fileSize = fileSize;
    diskFile.write((char*) & fInfo, sizeof (fInfo));
    FATBlock.size += sizeof (fInfo);
    diskFile.seekp((fatBlock - 1) * blkSize + sizeof (DiskInfo));
    diskFile.write((char*) & FATBlock, sizeof (FATBlock));
    return fatBlock;
}
Example #3
0
void CXMLTreeNode::getAttributeNames(string &names)
{
    // just to be safe, clear current value
    names.erase(names.begin(), names.end());  // using erase because clear not supported on VxWorks

    // add elements
    MapStringToNode::const_iterator iter = m_subNodesMap.begin();
    while (iter != m_subNodesMap.end())
	{
	names.append(iter->first.c_str()).append(",");
	iter++;
	}

    // and attributes
    MapStringToString::const_iterator fldIter = m_fieldMap.begin();
    while (fldIter != m_fieldMap.end()) {
    // filter out namespace information
    if(ACE_OS::strncmp(fldIter->first.c_str(), "xmlns", 5) != 0) {
    names.append(fldIter->first.c_str()).append(",");
    }
    fldIter++;
    }

    // if not empty, truncate last comma
    if (names.length())
	names.resize(names.length() - 1);
}
Example #4
0
static void sReadString(const ZStreamR& iStreamR, string& oString)
	{
	uint32 theCount = sReadCount(iStreamR);
	oString.resize(theCount);
	if (theCount)
		iStreamR.Read(const_cast<char*>(oString.data()), theCount);
	}
    /**
     * 深度优先搜索
     * @param s      [description]
     * @param start  本次开始的位置,指向字符串的指针
     * @param step   已经切割的ip地址段数,0,1,2,3,4
     * @param result 保存合法解
     */
    void DFS(string s, size_t start, size_t step, string ip,  vector<string > &result){
        if(start == s.size() && step == 4){ //递归出口,刚好切割到末尾,一个合法解
            ip.resize(ip.size() - 1);   //因为最后的循环会在末尾多加一个'.'
            result.push_back(ip);
            return;
        }


        //剪枝工作,加快效率,不剪枝的话就会超时
        //
        if(s.size() - start > (4 - step) * 3) return;   //每步划分过小,剩余太多,剪
        if(s.size() - start < 4 - step) return; //例如step == 2, 最后还剩不到两个,剪
        if(step >= 4) return;   //剪枝效果显著

        int num = 0;
        for(size_t i = start; i < start + 3; ++i ){
            num = num * 10 + (s[i] - '0');    //上一次的值拼上当前char的值

            if(num <= 255){
                ip += s[i]; //拼出来的值合法,拼上去
                DFS(s, i + 1, step + 1, ip + '.', result);
            }

            if(num == 0) break; //如果遇到0了,赶紧跳出,否则就会出现01.01这种0前缀,不合法
        }
    }
Example #6
0
 void partitionIP(string s, int startIndex, int partNum, string resultIP, vector<string>& col){
     // max: 3 bits per partition
     if (s.size() - startIndex > (4 - partNum) * 3){
         return;
     }
     // min: 1 bit per partition
     if (s.size() - startIndex < (4 - partNum)){
         return;
     }
     if (startIndex == s.size() && partNum == 4){
         resultIP.resize(resultIP.size() - 1);
         col.push_back(resultIP);
         return;
     }
     int num = 0;
     for (int i = startIndex; i < startIndex + 3; i++){
         num = num * 10 + (s[i] - '0');
         if (num <= 255){
             resultIP += s[i];
             partitionIP(s, i + 1, partNum + 1, resultIP + '.', col);
         }
         if (num == 0){  // 0.0.0.0 valid, but need to avoid 0.1.010.01
             break;
         }
     }
 }
Example #7
0
void _Log::clean_path( string& input ){
	if( input.length() == 0 ) return;

	//remove all spaces
	int check_index = input.find_first_not_of(' ');
	int write_index = 0;
	int temp_index;

	if( check_index == -1 ){
		input.clear();
		return;
	}

	while( check_index < input.length() ){
		if( input[check_index] != ' ' ){
			temp_index = check_index;
		}

		if( input[check_index] == '\\' ){
			check_index = input.find_first_not_of( '\\', check_index );
			if( check_index != -1 ){
				check_index--;
			} else {
				check_index = input.find_last_of( '\\' );
			}
		}

		input[write_index] = input[check_index];
		write_index++;
		check_index++;
	}


	input.resize( temp_index + 1 );
}
 void normal(string &x) {
   using namespace tool;
   if (x[x.size() - 1] == '/') x.resize(x.size() - 1);
   fix(x, "http://");
   fix(x, "www.bbc.com");
   if (!fix(x, "/news/") || x.size() > 300) x = "<ERROR>";
 }
Example #9
0
BOOL COciRecordSet::GetBlobCollect(const char* szFieldName,string& strValue)
{
	SQLCHAR*		pszData = NULL;
	try
	{
		// 当前字段的字节长度
		UINT		iActualDataSize = 0;

		// 分配内存
		if (m_pOciDeal->pOCI_IsNull2(this->m_pResultset, szFieldName))
		{		
			return FALSE;
		}

		OCI_Lob* lob = m_pOciDeal->pOCI_GetLob2(this->m_pResultset, szFieldName);
		iActualDataSize = m_pOciDeal->pOCI_LobGetLength(lob);

		if (iActualDataSize <= 0)
		{			
			return FALSE;
		}
		strValue.resize(iActualDataSize);
		m_pOciDeal->pOCI_LobRead(lob, (void*)strValue.c_str(), iActualDataSize);
		
	}
	catch(...)
	{
		strValue.clear();
		return	FALSE;
	}

	return TRUE;
}
Example #10
0
void INFO ::do_encode()
{
	unsigned int i=0;
	codemsg.resize(ai_len);
	string buff;
	buff.resize(ai_len);
	codemsg.assign(ai_len,' ');
	for(i=0;i<premsg.size();i++)
	{
		codemsg[key[i]]=premsg[i];
		//cout<<premsg[i]<<endl;
		//cout<<key[i]<<endl;
		//cout<<codemsg[key[i]]<<endl;
	}
	repeat_num--;
	if(repeat_num != 0)
	{
		while(repeat_num--)
		{
			buff.assign(ai_len,' ');
			for(i=0;i<ai_len;i++)
			{
				if(codemsg[i] != ' ')
					buff[key[i]]=codemsg[i];
			}
			buff.swap(codemsg);
		}
	}
	for(i=0;i<ai_len;i++)
	{
		cout<<codemsg[i];
	}
	cout<<endl;
}
Example #11
0
bool CreatePath(string &sPath)
{
	DWORD attr;
	int pos;
	bool result = true;

	// Check for trailing slash:
	pos = sPath.find_last_of('\\');
	if (sPath.length() == pos + 1)	// last character is "\"
	{
		sPath.resize(pos);
	}

	// Look for existing object:
	attr = GetFileAttributesA(sPath.c_str());
	if (0xFFFFFFFF == attr)	// doesn't exist yet - create it!
	{
		pos = sPath.find_last_of('\\');
		if (0 < pos)
		{
			// Create parent dirs:
			result = CreatePath(sPath.substr(0, pos));
		}
		// Create node:
		result = result && CreateDirectoryA(sPath.c_str(), NULL);
	}
	else if (FILE_ATTRIBUTE_DIRECTORY != attr)
	{	// object already exists, but is not a dir
		SetLastError(ERROR_FILE_EXISTS);
		result = false;
	}

	return result;
}
Example #12
0
void ProcessDirectory(std::string directory, stack<string>& output)
{
    std::string dirToOpen = __temp_root_path + directory;
    DIR *dir = opendir(dirToOpen.c_str());

    //set the new path for the content of the directory
    __temp_root_path = dirToOpen + "/";

    //Output dirToOpen.c_str();
    //std::cout << "Process directory: " << dirToOpen.c_str() << std::endl;
    output.push(dirToOpen);

    if(NULL == dir)
    {
        std::cout << "could not open directory: " << dirToOpen.c_str() << std::endl;
        return;
    }

    struct dirent *entity = readdir(dir);

    while(entity != NULL)
    {
        ProcessEntity(entity,output);
        entity = readdir(dir);
    }

    //we finished with the directory so remove it from the path
    __temp_root_path.resize(__temp_root_path.length() - 1 - directory.length());
    closedir(dir);
}
void replace_and_remove(string &s){
	int a_count=0, idx = 0;
	//delete b first
	for(const char &c:s){
		if(c=='a'){
			s[idx++] = c;
			a_count++;
		}else if(c=='b'){
			continue;
		}else{//not 'a' nor 'b'
			s[idx++] = c;		
		}
	}
	int cur = idx+a_count-1;
	s.resize(idx+a_count);
	for(int i = idx-1;i>=0;i--){
		if(s[i]=='a'){
			s[cur] = 'd';
			s[cur-1] = 'd';
			cur -=2; 
		}else{
			s[cur] = s[i];
			cur--;
		}
	}
}
Example #14
0
static void PrepareOptFolder(string &strSrc, int IsLocalPath_FarPath)
{
	if (strSrc.empty())
	{
		strSrc = Global->g_strFarPath;
		DeleteEndSlash(strSrc);
	}
	else
	{
		strSrc = os::env::expand_strings(strSrc);
	}

	if (strSrc == L"/")
	{
		strSrc = Global->g_strFarPath;

		if (IsLocalPath_FarPath)
		{
			strSrc.resize(2);
			strSrc += L"\\";
		}
	}
	else
	{
		CheckShortcutFolder(strSrc, true, true);
	}

	//ConvertNameToFull(strSrc,strSrc);
}
Example #15
0
/*---------------------------------------------------------------
						getText
  ---------------------------------------------------------------*/
void  CStringList::getText(string &outText) const
{
	MRPT_START
	deque<string>::const_iterator	it;
	size_t								curPos = 0,totalLen = 0;

	// 1) Compute overall length, including 2 chars per new-line:
	// ----------------------------------------------------------------
	for (it=m_strings.begin();it!=m_strings.end();it++)
		totalLen += it->size() + 2;

	outText.resize(totalLen);

	// 2) Copy the text out:
	// ----------------------------------------------------------------
	for (it=m_strings.begin();it!=m_strings.end();it++)
	{
		os::memcpy(&outText[curPos],totalLen,it->c_str(),it->size());
		curPos+=it->size();
		outText[curPos++]='\r';
		outText[curPos++]='\n';
	}

	MRPT_END
}
Example #16
0
    string simplifyPath(string path) {
		if(!path.size())
			return path;
		if(path[0] != '/')
			return string();
			
		int i = 0;
		int j = 1;
		while(j < path.size()) {
			if(path[j]=='.' && (j+1<path.size()&&path[j+1]=='/' || j==path.size()-1))
				j += 2;
			else if(path[j]=='.' && j+1<path.size() && path[j+1]=='.' && (j+2>=path.size()||path[j+2]=='/')) {
				while(i>0 && path[i] != '/')
					--i;
				if(i>0 && path[i] == '/')
					--i;
					
				j += 3;
			} else if(path[j] == '/') {
				++j;
			}
			else {
				if(path[i] != '/')
					path[++i] = '/';
				while(j<path.size() && path[j]!='/') {
					path[++i] = path[j++];
				}
			}
		}
		
		path.resize(i+1);
		return path;
    }
Example #17
0
ObjectHandle Object::construct(string str)
{
	size_t right = str.find("|");
	if (right != string::npos) str.resize(right);
	if (!Constructor::list.count(str)) return Object();
	return Constructor::list[str]();
}
Example #18
0
void GVector::getStr(string&str,cstr name){
    ulong *size;
    string name_=name;
    ulong indexRecord=0;
    string strName; getName(strName);
    //cout<<"strName="<<strName<<endl;
    if(strName.size()<5){str="";return;}
    vector<string>indexName=explode(":|:",strName);
    //cout<<"indexName[a].size()="<<indexName.size()<<endl;
    
    for(int a=0; a<indexName.size()-1;a++){
        string st=indexName[a];
        if(indexName[a]==name_){
            //cout<<"name="<<indexName[a];
            memcpy(&indexRecord,&indexName[a+1][0],4);
            //cout<<"indexRecord="<<indexRecord<<" *recordCount="<<*recordCount<<endl;
            //cout<<"index[indexRecord]="<<index[indexRecord]<<endl;
            break;
        }
    }
    if(indexRecord>*recordCount||indexRecord==0){str="";return;}
    size=(ulong*)(data+index[indexRecord]);
    if(*size==0){str="";return;}
    //cout<<"size="<<*size<<endl;
    str.resize(*size);
    memcpy(&str[0],(data+index[indexRecord]+4),*size);
    
};
bool xml_istream::collapse_whitespace(const string& s, string& ts)
{
    ts.clear();

    const size_t k = s.length();
    size_t i = 0;

    parse_ws(s, i); /* Ignore leading whitespace. */

    for (; i < k; ++i)
    {
        if (is_ws_char(s[i]) != false)
        {
            ts += ' ';
            ++i;
            for (; i < k && is_ws_char(s[i]) != false; ++i);
            --i;
        }
        else
        {
            ts += s[i];
        }
    }

    size_t last = ts.length() - 1;
    if (is_ws_char(ts[last]) != false) /* Remove tailing whitespace. */
    {
        ts.resize(last);
    }

    return ts.length() < k;
}
Example #20
0
void GVector::getName(string&str){
    ulong *size;
    size=(ulong*)(data+index[0]);
    //cout<<"size="<<*size<<" index[0]="<<index[0]<<endl;
    str.resize(*size);
    memcpy(&str[0],(data+index[0]+8),*size);
};
/**
	Process iteratively all the directories within the given directory. Inside each directory, all the files are processed.
	The name of the file processed is saved in a file.
	@param path: path to the directory to process
	@param name: name of the directory to process

*/
void DatasetGenerator::processDirectory(string &path, const string &directory)
{
	//Save dir name if file
	dirNames<<path+directory<<endl;

	//Open directory and add dir to the path
	string dirToOpen=path+directory;
	auto dir=opendir(dirToOpen.c_str());
	path=dirToOpen+'/';

	if(dir==NULL){
		cout << "Could not open directory "<<dirToOpen<<endl;
		return;
	}
	//Read directory and process items
	struct dirent* entity=readdir(dir);
	while(entity!=NULL)
	{
		processEntity(path, entity);
		entity= readdir(dir);
	}
	//Remove dir from the path
	path.resize(path.length() -1 -directory.length());
	closedir(dir);
}
Example #22
0
 string transform(string source)
 {
     int length = source.length();
     int cnt_a = 0, cnt_b = 0;
     for(int i = 0; i < length; i++)
         if(source[i] == 'A')
             cnt_a++;
         else if(source[i] == 'B')
             cnt_b++;
     int target_len = length - cnt_a + cnt_b;
     if(target_len > length)
         throw new exception();
     int i = 0, j = 0;
     while(j < length && source[j] == 'A')
         j++;
     while(i < target_len && j < length)
     {
         source[i++] = source[j++];
         while(j < length && source[j] == 'A')
             j++;
     }
     i = length - cnt_a - 1;
     j = target_len - 1;
     while(i >= 0 && j >= 0)
     {
         source[j--] = source[i];
         if(source[i] == 'B')
             source[j--] = 'B';
         i--;
     }
     source.resize(target_len);
     return source;
 }
void SerialLine::read(string& buffer, int max_len, double timeout)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR2(max_len, timeout);

	buffer.resize(max_len);
	char *ptr = max_len ? (char *) buffer.data() : NULL;
	unsigned long ret_len = max_len;
	unsigned long tmout = Sec2USec(checkDefTimeout(timeout));

	DEB_TRACE() << "Calling espia_ser_read";
	CHECK_CALL(espia_ser_read(m_dev, ptr, &ret_len, tmout));
	buffer.resize(ret_len);

	DEB_RETURN() << DEB_VAR1(buffer);
}
Example #24
0
bool CppSeqFile::Reader::nextRaw(string& key, string& value)
{
  if (_in.eof())
  {
    return false;
  }
  else
  {
    int recordLength = _dis.readInt();
    if (_in.eof())
    {
      return false;
    }
    if (recordLength == -1)
    {
      _verifySync();
      recordLength = _dis.readInt();
      _syncSeen = true;
      if (_in.eof() || _in.gcount() == 0)
      {
        return false;
      }
    }
    else
    {
      _syncSeen = false;
    }
    if (recordLength <= 0)
    {
      throw Exception(QString("Record length was not positive. (recordLength: %1 position: %2)").
        arg(recordLength).arg(_in.tellg()).toStdString());
    }

    int keyLength = _dis.readInt();
    if (_in.gcount() == 0 || _in.eof())
    {
      return false;
    }
    int valueLength = recordLength - sizeof(int32_t) * 2 - keyLength;
    key.resize(keyLength);
    value.resize(valueLength);
    _dis.read((char*)key.data(), keyLength);
    _dis.read((char*)value.data(), valueLength);

    return true;
  }
}
Example #25
0
void BinaryDict::ConstructBuffer(string& keyBuffer, vector<size_t>& keyOffset,
                                 size_t& keyTotalLength, string& valueBuffer,
                                 vector<size_t>& valueOffset,
                                 size_t& valueTotalLength) const {
  keyTotalLength = 0;
  valueTotalLength = 0;
  // Calculate total length
  for (const DictEntry* entry : *lexicon) {
    keyTotalLength += entry->KeyLength() + 1;
    assert(entry->NumValues() != 0);
    if (entry->NumValues() == 1) {
      const auto* svEntry = static_cast<const SingleValueDictEntry*>(entry);
      valueTotalLength += strlen(svEntry->Value()) + 1;
    } else {
      const auto* mvEntry = static_cast<const MultiValueDictEntry*>(entry);
      for (const auto& value : mvEntry->Values()) {
        valueTotalLength += strlen(value) + 1;
      }
    }
  }
  // Write keys and values to buffers
  keyBuffer.resize(keyTotalLength, '\0');
  valueBuffer.resize(valueTotalLength, '\0');
  char* pKeyBuffer = const_cast<char*>(keyBuffer.c_str());
  char* pValueBuffer = const_cast<char*>(valueBuffer.c_str());
  for (const DictEntry* entry : *lexicon) {
    strcpy(pKeyBuffer, entry->Key());
    keyOffset.push_back(pKeyBuffer - keyBuffer.c_str());
    pKeyBuffer += entry->KeyLength() + 1;
    if (entry->NumValues() == 1) {
      const auto* svEntry = static_cast<const SingleValueDictEntry*>(entry);
      strcpy(pValueBuffer, svEntry->Value());
      valueOffset.push_back(pValueBuffer - valueBuffer.c_str());
      pValueBuffer += strlen(svEntry->Value()) + 1;
    } else {
      const auto* mvEntry = static_cast<const MultiValueDictEntry*>(entry);
      for (const auto& value : mvEntry->Values()) {
        strcpy(pValueBuffer, value);
        valueOffset.push_back(pValueBuffer - valueBuffer.c_str());
        pValueBuffer += strlen(value) + 1;
      }
    }
  }
  assert(keyBuffer.c_str() + keyTotalLength == pKeyBuffer);
  assert(valueBuffer.c_str() + valueTotalLength == pValueBuffer);
}
Example #26
0
void generateParString(int numleftPar, int numrightPar, string& current, vector<string>& res, const int n) {
       if(numleftPar + numrightPar == 2*n) {
		res.push_back(current);
		return;
       }
       if(numleftPar<n) {
		current.push_back('(');
		generateParString(numleftPar + 1, numrightPar, current, res, n);
		current.resize(current.size() - 1);
       }
       if(numrightPar<numleftPar) {
	       current.push_back(')');
	       generateParString(numleftPar, numrightPar + 1, current, res, n);
	       current.resize(current.size() - 1);
       }
       return;
}
Example #27
0
// convert int from Nmer2Int back to a string
void CNucProp::Int2Nmer(int nmer_int, int nmer_size, string& out)
{
    out.resize(nmer_size);
    for (int i = nmer_size-1;  i >= 0; i--) {
        out[i] = Nybble2Nuc(nmer_int & 3);   // analyze two low-order bits
        nmer_int >>= 2;
    }
}
Example #28
0
void cleanname(string &s)
{
  string::iterator it;

  it = remove(s.begin(), s.end(), '\'');
  it = remove(s.begin(), it, '-');
  s.resize(it - s.begin());
}
Example #29
0
void CodeClear::Trim(string &str)
{
    if(str[0] == ' ')
    {
        for(int i = 0; i < (int)str.size(); i++)
        {
            str[i] = str[i+1];
        }

        str.resize(str.size() - 1);
    }

    if(str[str.size()] == ' ')
    {
        str.resize(str.size() - 1);
    }
}
Example #30
0
	void BinReader::_serialize( string& nValue, const wchar_t * nName, const char * nOptimal )
	{
		__u16 count_ = 0;
		__i8 value_ = 0;
		mStream.read((char *)(&count_), sizeof(__u16));
		nValue.resize(count_);
		mStream.read(&nValue[0], count_);
	}