示例#1
0
LString LString::operator +(const LString &o) const {
    if (this->isEmpty()) return o;
    if (o.isEmpty()) return *this;

    LStringData *newStr = LStringData::create(this->length() + o.length() + 1);
    std::copy(this->mData->begin(), this->mData->end(), newStr->begin());
    std::copy(o.mData->begin(), o.mData->end(), newStr->begin() + this->length());

    newStr->mSize = this->length() + o.length();
    return LString(newStr);
}
示例#2
0
  LString readStr(int start, int end) {
    if (m_recbuf.isEmpty()) return LString();

    start --; end --;
    if (end >= m_recbuf.length())
      end = m_recbuf.length()-1;
    if (start<0)
      start = 0;
    if (start>end)
      start = end;

    return m_recbuf.substr(start, end-start+1);
  }
示例#3
0
void PrintStream::print(const LString &n)
{
  int len = n.length();
  int res = write(n.c_str(), 0, len);
  if (res!=len)
    MB_THROW(IOException, LString::format("OutStream.write() failed. (%d:%d)", res, len));
}
示例#4
0
  int readOneImpl() {
    int i;
    std::deque<unsigned char> cmp;
    for (i=0; i<m_nextMark.length(); ++i) {
      int c = qread();
      if (c>=0) {
        cmp.push_front(c);
        if (c==m_nextMark[i]) {
	  // MB_DPRINTLN("MM> %s", m_nextMark.substr(0, i).c_str());
          continue;
	}
      }
      else {

        // EOF
        if (cmp.size()<=0)
          break;
      }

      unsigned char ret = cmp.back();
      cmp.pop_back();
      std::deque<unsigned char>::const_iterator iter = cmp.begin();
      std::deque<unsigned char>::const_iterator iend = cmp.end();
      for (; iter!=iend; ++iter)
        unread(*iter);
      return ret;

    }

    m_bReady = false;
    return -1;
  }
示例#5
0
 void setMark(const LString &mark) {
   m_bReady = true;
   m_mark = mark;
   m_nCbufLen = m_mark.length();
   m_cbuf.set_capacity(m_nCbufLen);
   m_nMatch = 0;
 }
示例#6
0
LStr::clStringsVector clConsole::GetAutocompleteCommand( const LString& CMDName ) const
{
	LStr::clStringsVector Result;

	if ( CMDName.empty() ) { return Result; }

	LString CMD = LStr::GetUpper( CMDName );
	size_t Len = CMD.length();

	bool Lower = LStr::IsLower( CMDName[CMDName.size()-1] );

	for ( clCommandsList::const_iterator i = FCommandsList.begin(); i != FCommandsList.end(); ++i )
	{
		if ( LStr::StartsWith( i->first, CMD ) )
		{
			LString Tail = LStr::CopyFromPosToEnd( i->first, Len );
			Result.push_back( CMDName + ( Lower ? LStr::GetLower( Tail ) : Tail ) );
		}
	}

	for ( clAliasesList::const_iterator i = FAliasesList.begin(); i != FAliasesList.end(); ++i )
	{
		if ( LStr::StartsWith( i->first, CMD ) )
		{
			LString Tail = LStr::CopyFromPosToEnd( i->first, Len );
			Result.push_back( CMDName + ( Lower ? LStr::GetLower( Tail ) : Tail ) );
		}
	}

	return Result;
}
/**
   This will convert requested filename with full path into a single file name
    e.g.  c:\\data\\textures\\texture1.tga
          c~_data_textures_texture1.tga
**/
LString clResourcesManager::ConvertName( const LString& FileName )
{
	LString ConvName;

	for ( size_t i = 0; i < FileName.length(); ++i )
	{
		switch ( FileName[i] )
		{
			case '\\':
			case '/':
			{
				ConvName.push_back( '_' );
				continue;
			}
			case ':':
			{
				ConvName.push_back( '~' );
				continue;
			}
			case ' ':
			{
				ConvName.push_back( '#' );
				continue;
			}
		}

		ConvName.push_back( FileName[i] );
	}

	return ConvName;
}
示例#8
0
    void getRec(int pos, int unit, LString &ret)
    {
      int beg = pos*unit;

      if (beg>=m_line.length() ||
          beg<0) {
        MB_THROW(qlib::FileFormatException, "");
        return;
      }

      ret = m_line.substr(beg, unit);
    }
示例#9
0
void clConsole::DisplayMessage( const LString& Message, const LConsoleMessageType MSGType ) const
{
	if ( Env )
	{
		Env->SendSync( L_EVENT_CONSOLELOG, LEventArgs( &Message ), false );
	}

	FTimeVisible = MESSAGE_VISIBILITY_TIME;

	LVector4 Color;

	switch ( MSGType )
	{
		case CMSG_ENGINEMESSAGE:
			Color = LC_LinderdaumConsoleEM;
			break;
		case CMSG_ERRORMESSAGE:
			Color = LC_LinderdaumConsoleERR;
			break;
		case CMSG_INFOTIP:
			Color = LC_LinderdaumConsoleIT;
			break;
		default:
			FATAL_MSG( "Unknown message type" );
	}

	LString Msg = Message;

	LMutex Lock( &FMessagesHistoryMutex );

	while ( true )
	{
		size_t Separation = Msg.find( "\n" );

		if ( Separation == LString::npos )
		{
			break;
		}

		LString NewMsg = Msg.substr( 0, Separation );

		FMessagesHistory.push_back( sConsoleMessage( NewMsg, Color ) );

		if ( FMessagesHistory.size() > MAX_HISTORY_SIZE )
		{
			FMessagesHistory.pop_front();
		}

		Msg = Msg.substr( Separation + 1, Message.length() - 1 );
	}

	FMessagesHistory.push_back( sConsoleMessage( Msg, Color ) );
}
示例#10
0
LString PDBFileWriter::formatAtomName(MolAtomPtr pAtom)
{
  LString atomnam = pAtom->getName();
  char cConfID = pAtom->getConfID();
  int elem = pAtom->getElement();
  
  if (cConfID=='\0')
    cConfID = ' ';

  // invalid name case
  if (atomnam.length()>=4||
      elem==ElemSym::XX) {
    return LString::format("%4s%c", atomnam.c_str(), cConfID);
  }

  LString elenam = ElemSym::symID2Str(elem);
  elenam = elenam.toUpperCase();
  int elepos = atomnam.indexOf(elenam);
  if (elepos<0) {
    return LString::format("%4s%c", atomnam.c_str(), cConfID);
  }
  
  LString atommod;
  // if (atomnam.equals(elenam)) {
  // // atom name==elem name
  // shead += LString::format(" %2s  ", elenam.c_str());
  // break;
  // }
  
  elepos += elenam.length();
  atommod = atomnam.substr(elepos);
  elenam = atomnam.substr(0, elepos);
  
  if (atommod.length()<=2) {
    return LString::format("%2s%-2s%c",
                           elenam.c_str(), atommod.c_str(), cConfID);
  }
  
  return LString::format("%4s%c", atomnam.c_str(), cConfID);
}
示例#11
0
    int getInt(int pos, int unit)
    {
      int ret;
      int beg = pos*unit;

      if (beg>=m_line.length() ||
          beg<0) {
        MB_THROW(qlib::FileFormatException, "");
        return -1;
      }

      LString s = m_line.substr(beg, unit);
      if (!s.toInt(&ret)) {
        MB_THROW(qlib::FileFormatException, "");
        return -1;
      }
      return ret;
    }
示例#12
0
size_t clConsole::FindCommandsSeparator( const LString& CMDString ) const
{
	bool InToken = false;

	for ( size_t i = 0; i != CMDString.length(); ++i )
	{
		if ( CMDString[i] == '"' )
		{
			InToken = !InToken;
		}

		if ( CMDString[i] == ';' && !InToken )
		{
			return i;
		}
	}

	return 0;
}
示例#13
0
void clLocalizer::SetLocale( const LString& LocaleName )
{
	guard( "%s", LocaleName.c_str() );

	ClearLocalization();

	FLocaleName = LocaleName;

	const LString FileName( FLocalePath + "/Localizer-" + LocaleName + ".txt" );

	if ( Env->FileSystem->FileExists( FileName ) )
	{
		Env->Logger->LogP( L_NOTICE, "Reading locale from %s", FileName.c_str() );

		iIStream* Stream = Env->FileSystem->CreateFileReader( FileName );

		while ( !Stream->Eof() )
		{
			LString Line = Stream->ReadLine();

			size_t SepPos = Line.find( "~" );

			FATAL( SepPos == Line.npos, "Invalid locale translation file format: missing ~" );

			LString Text( Line.substr( 0, SepPos ) );
			LString Translation( Line.substr( SepPos + 1, Line.length() - SepPos - 1 ) );

			FTranslations[ Text ] = Translation;
		}

		delete( Stream );
	}
	else
	{
		Env->Logger->LogP( L_NOTICE, "Locale %s not found", FileName.c_str() );
	}

	this->SendAsync( L_EVENT_LOCALE_CHANGED, LEventArgs(), false );

	unguard();
}
示例#14
0
int LString::indexOf(const LString &str, int start) const {
    if (str.length() > this->length()) return -1;
    if (str.length() == 1) return indexOf(str[0], start);

    ConstIterator si = str.cbegin();
    int indexCounter = start;
    int index = 0;
    for (ConstIterator i = at(start); i != cend(); i++, indexCounter++) {
        if (*si == *i) {
            if (si == str.cbegin()) {
                index = indexCounter;
            }
            si++;
            if (si == str.cend()) {
                return index;
            }
            continue;
        }

        si = str.cbegin();
    }
    return -1;
}
示例#15
0
void clViewport::DrawText( int X, int Y, const LString& Text )
{
#ifdef OS_WINDOWS
    TextOut( FDeviceHandle, X, Y, Text.c_str(), static_cast<int>( Text.length() ) );
#endif
}
示例#16
0
void clConsole::SendCommand( const LString& CMDName )
{
	guard( "%s", CMDName.c_str() );

	FSendCommandResult.assign( "" );

	if ( CMDName.size() == 0 )
	{
		return;
	}

	bool IsScript = ( LStr::GetUpper( LStr::GetToken( CMDName, 1 ) ) == "RS" );

	// split command
	size_t CommandsSeparator = FindCommandsSeparator( CMDName );

	LString ThisCMDString = CMDName;
	LString RestCMDString( "" );

	if ( !IsScript )
	{
		if ( CommandsSeparator )
		{
			ThisCMDString = CMDName.substr( 0, CommandsSeparator );
			RestCMDString = CMDName.substr( CommandsSeparator,
			                                CMDName.length() - CommandsSeparator );

			if ( RestCMDString.length() > 0 )
			{
				LStr::pop_front( &RestCMDString );
			}
		}
	}

	// extract command name and parameters
	LString ThisCMDName  = LStr::GetToken( ThisCMDString, 1 );
	LString ThisCMDParam = ThisCMDString.substr( ThisCMDName.length(),
	                                             ThisCMDString.length() - ThisCMDName.length() );

	if ( ThisCMDParam.length() > 0 )
	{
		LStr::pop_front( &ThisCMDParam );
	}

	LStr::ToUpper( &ThisCMDName );

	if ( IsScript )
	{
		// execute script and return
		ExecuteStatement( ThisCMDParam );

		return;
	}

	if ( ThisCMDName.find( "WAIT" ) == 0 )
	{
		// Leave the rest of the command until the next frame
		if ( CommandsSeparator )
		{
			QueryCommand( RestCMDString );
		}

		return;
	}
	else
	{
		clCommandsList::const_iterator i = FCommandsList.find( ThisCMDName );

		if ( i != FCommandsList.end() )
		{
			( i->second ).Exec( clFileSystem::ReplaceEnvVars( ThisCMDParam ) );
		}
		else
		{
			clAliasesList::const_iterator j = FAliasesList.find( ThisCMDName );

			if ( j != FAliasesList.end() )
			{
				QueryCommand( j->second );
			}
			else
			{
				DisplayError( "Unknown command: " + ThisCMDName );
			}
		}
	}

	if ( CommandsSeparator )
	{
		SendCommand( RestCMDString );
	}

	unguard();
}
示例#17
0
void PDBFileWriter::writeSecstr(qlib::PrintStream &prs)
{
  MolResiduePtr pRes1;

  int nhx = 1;
  MolCoordPtr pMol(m_pMol);
  ResidIterator riter(pMol); //(MolCoordPtr(m_pMol));

  // Write HELIX records
  for (riter.first(); riter.hasMore(); riter.next()) {
    LString sec;
    LString pfx;
    MolResiduePtr pRes = riter.get();
    pRes->getPropStr("secondary2", sec);

    // MB_DPRINTLN("%s%d => %s", pRes->getChainName().c_str(), pRes->getIndex().first, sec.c_str());

    if (sec.length()>=2)
      pfx= sec.substr(1,1);
    
    if (!(sec.startsWith("H")||sec.startsWith("G")||sec.startsWith("I")))
      continue;

    if (pfx.equals("s"))
      pRes1 = pRes;
    else if (pfx.equals("e")) {
      LString resn1 = pRes1->getName().substr(0,3);
      LString chn1 = pRes1->getChainName().substr(0,1);
      ResidIndex resix1 = pRes1->getIndex();
      char ins1 = resix1.second;
        if (ins1=='\0') ins1 = ' ';
      
      LString resn2 = pRes->getName().substr(0,3);
      LString chn2 = pRes->getChainName().substr(0,1);
      ResidIndex resix2 = pRes->getIndex();
      char ins2 = resix2.second;
      if (ins2=='\0') ins2 = ' ';
      
      prs.print("HELIX ");
      // helix seqno
      prs.format(" %3d", nhx);
        // helix ID
      prs.format(" %3d", nhx);
      
      // start resname
      prs.format(" %3s", resn1.c_str());
      prs.format(" %1s", chn1.c_str());
      prs.format(" %4d", resix1.first);
      prs.format("%c", ins1);
      
      // end resname
      prs.format(" %3s", resn2.c_str());
      prs.format(" %1s", chn2.c_str());
      prs.format(" %4d", resix2.first);
      prs.format("%c", ins2);
      
      // typeof helix
      int ntype = 1;
      if (sec.startsWith("G"))
        ntype = 5;
      else if (sec.startsWith("I"))
        ntype = 3;
      prs.format("%2d", ntype);
      
      prs.println("");
      ++nhx;
    }
  }

  // Write SHEET records
  int nsh = 1;
  for (riter.first(); riter.hasMore(); riter.next()) {
    LString sec;
    LString pfx;
    MolResiduePtr pRes = riter.get();
    pRes->getPropStr("secondary2", sec);

    // MB_DPRINTLN("%s%d => %s", pRes->getChainName().c_str(), pRes->getIndex().first, sec.c_str());

    if (sec.length()>=2)
      pfx= sec.substr(1,1);
    
    if (!(sec.startsWith("E")))
      continue;

    if (pfx.equals("s"))
      pRes1 = pRes;
    else if (pfx.equals("e")) {
      
      LString resn1 = pRes1->getName().substr(0,3);
      LString chn1 = pRes1->getChainName().substr(0,1);
      ResidIndex resix1 = pRes1->getIndex();
      char ins1 = resix1.second;
      if (ins1=='\0') ins1 = ' ';
      
      LString resn2 = pRes->getName().substr(0,3);
      LString chn2 = pRes->getChainName().substr(0,1);
      ResidIndex resix2 = pRes->getIndex();
      char ins2 = resix2.second;
      if (ins2=='\0') ins2 = ' ';
      
      prs.print("SHEET ");
      // helix seqno
      prs.format(" %3d", nsh);
      // helix ID
      prs.format(" %3d", nsh);
      // num of strands
      prs.print(" 1");

      // start resname
      prs.format(" %3s", resn1.c_str());
      prs.format(" %1s", chn1.c_str());
      prs.format("%4d", resix1.first);
      prs.format("%c", ins1);
      
      // end resname
      prs.format(" %3s", resn2.c_str());
      prs.format(" %1s", chn2.c_str());
      prs.format("%4d", resix2.first);
      prs.format("%c", ins2);
      
      // direction
      prs.print(" 0");

      prs.println("");
      ++nsh;
    }
  } // for

}
示例#18
0
void SceneXMLReader::procDataSrcLoad(qlib::LDom2InStream &ois, LDom2Node *pNode)
{
  //////////
  // Recursively check the data src load requests

  LDom2Node::NodeList::const_iterator iter = pNode->childBegin();
  LDom2Node::NodeList::const_iterator eiter = pNode->childEnd();
  for (; iter!=eiter; ++iter) {
    LDom2Node *pChNode = *iter;
    if (pChNode!=NULL)
      procDataSrcLoad(ois, pChNode);
  }

  //////////
  // Do data source loading

  LDataSrcContainer *pCnt = pNode->getDataSrcContainer();
  if (pCnt==NULL)
    return;
  
  LString src = pNode->getDataSrc();
  LString altsrc = pNode->getDataAltSrc();
  LString srctype = pNode->getDataSrcType();

  if (src.isEmpty())
    return;

  if (srctype.isEmpty()) {
    // ERROR!! (TO DO: handling)
    LOG_DPRINTLN("SceneXML> src %s: srctype is not defined. (ignored)", src.c_str());
    return;
  }

  if (src.startsWith("datachunk:") && src.length()==15) {
    // Data source is in datachunk
    // --> Prepare for reading from data chunk of the stream
    MB_DPRINTLN("Data chunk found %s, %s ",
                src.c_str(), srctype.c_str());
    // addChunkMap(src, pCnt, srctype);
    ois.addChunkMap(src, pCnt);
    return;
  }
  
  //robj->readFromPath(src, altsrc, m_pClient);
  bool bAlt = false;
  LString basedir = m_pClient->getBasePath();
  LString abs_path = pCnt->readFromSrcAltSrc(src, altsrc, basedir, bAlt);

  // ATTN 14/06/29:
  // Update src/altsrc properties based on where the data source has been loaded.
  // (In the qsc file, there are two alternative sources. However, only one src is actually loaded.)
  // This is required to keep consistency between the "src prop" and "actual data src".
  if (bAlt) {
    // loaded from altsrc; altsrc --> src
    if (!qlib::isAbsolutePath(altsrc))
      altsrc = qlib::makeAbsolutePath(altsrc, basedir);
    pCnt->updateSrcPath(altsrc);
  }
  else {
    // loaded from src; keep src
    if (!qlib::isAbsolutePath(src))
      src = qlib::makeAbsolutePath(src, basedir);
    pCnt->updateSrcPath(src);
  }

}