Example #1
0
void Wikidiff2::explodeLines(const String & text, StringVector &lines)
{
	String::const_iterator ptr = text.begin();
	while (ptr != text.end()) {
		String::const_iterator ptr2 = std::find(ptr, text.end(), '\n');
		lines.push_back(String(ptr, ptr2));

		ptr = ptr2;
		if (ptr != text.end()) {
			++ptr;
		}
	}
}
Example #2
0
void Label::setText(const String& text) {
  removeAllChildrenAndCleanup();
  text_ = text;
  float offset = 0;
  String::ConstIterator it = text.begin();
  for (; it != text.end(); ++it) {
    FontCharacterInfo character_info = font_->charInfo((*it));
    FontCharacter* character = FontCharacter::character(&character_info);
    character->setPosition(offset, 0);
    addChild(character);
    offset += character_info.width;
  }
}
Example #3
0
String REPLLineNoise::GetCurrentID(const String& CurrentLine)
{
    String::const_iterator Iter = CurrentLine.end();
    if(CurrentLine.begin() == Iter)
        { return String(); }
    String Results;
    Boole Started = false;
    // Start from end of string looking for characters which are valid in Lua Identifiers
    for(Iter--; Iter != CurrentLine.begin(); Iter--)
    {
        if(Scripting::Lua::Lua51ScriptingEngine::IsValidCharInTableIdentifier(*Iter))
        {
            Results = *Iter + Results;
            Started = true;
        }else{
            if(Scripting::Lua::Lua51ScriptingEngine::IsValidCharStartIdentifier(*(Iter+1)) && Started)
                { return String(Iter+1,CurrentLine.end()); }
            return String();
        }
    }
    return CurrentLine;
}
//-----------------------------------------------------------------------
Object* ApkZipArchiveFactory::createInstance(const String& name, const String& guid = BLANK)
{
	String apkName = name;
	if (apkName.size() > 0 && apkName[0] == '/')
		apkName.erase(apkName.begin());

	AAsset* asset = AAssetManager_open(mAssetMgr, apkName.c_str(), AASSET_MODE_BUFFER);
	if (asset)
	{
		EmbeddedZipArchiveFactory::addEmbbeddedFile(apkName, (const u2::u2uint8*)AAsset_getBuffer(asset), AAsset_getLength(asset), 0);
	}

	return EmbeddedZipArchiveFactory::createInstance(apkName, guid);
}
Example #5
0
void nsPluginInstance::StreamAsFile(NPStream* stream, const char* fname)
{
    printf("Pandora: compiling source\n");
    // compile the file, error reports need to go to the JS console
    // if successful, script level functions get proxies generated
    try {
        metadata->readEvalFile(fname);    
        for (LocalBindingIterator bi = metadata->glob->localBindings.begin(), 
				    bend = metadata->glob->localBindings.end(); (bi != bend); bi++) {
            LocalBindingEntry *lbe = *bi;
            for (LocalBindingEntry::NS_Iterator i = lbe->begin(), end = lbe->end(); (i != end); i++) {
                LocalBindingEntry::NamespaceBinding ns = *i;
                LocalMember *m = checked_cast<LocalMember *>(ns.second->content);
                switch (m->memberKind) {
                case Member::FrameVariableMember:
                    {
                        FrameVariable *fv = checked_cast<FrameVariable *>(m);
					    js2val v = (*metadata->glob->frameSlots)[fv->frameSlot];
					    if (JS2VAL_IS_OBJECT(v) 
							    && (JS2VAL_TO_OBJECT(v)->kind == SimpleInstanceKind)
							    && (checked_cast<SimpleInstance *>(JS2VAL_TO_OBJECT(v))->type == metadata->functionClass)
							    ) {
						    FunctionInstance *fnInst = checked_cast<FunctionInstance *>(JS2VAL_TO_OBJECT(v));

						    String fnName = lbe->name;
                    
						    std::string fstr(fnName.length(), char());
						    std::transform(fnName.begin(), fnName.end(), fstr.begin(), narrow);

                            printf("Pandora: adding wrapper for \"%s\"\n", fstr.c_str());
                
						    StringFormatter sf;
						    printFormat(sf, "JavaScript:function %s() { return document.js2.invoke(\"%s\"); }", fstr.c_str(), fstr.c_str());
						    std::string str(sf.getString().length(), char());
						    std::transform(sf.getString().begin(), sf.getString().end(), str.begin(), narrow);
						    NPN_GetURL(mInstance, str.c_str(), NULL);
					    }
					    
                    }
                    break;
			    }

            }		    
        }
        printf("Pandora: done compiling source\n");
    }
    catch (Exception x) {
        report(x);
    }
}
Example #6
0
int main(int argc, char * argv[])
{
	if(argc < 4)
	{
		std::cout << "Usage: " << argv[0] << " first last password" << std::endl;
		return 0;
	}
	try
	{
		logger::init();
		boost::asio::io_service service;
		boost::asio::ssl::context ctx(service, boost::asio::ssl::context::sslv23);
		ctx.set_options(boost::asio::ssl::context::default_workarounds);
		ctx.set_verify_mode(boost::asio::ssl::context::verify_peer);
		ctx.load_verify_file("data/ca.pem");	

		{		
			HTTPSClient::Pointer ptr = HTTPSClient::create(ctx, service);	
			HTTPRequest request(LLURI("https://login.agni.lindenlab.com/cgi-bin/login.cgi"),HTTP::METHOD::POST);
			String llsd = "<llsd>" + build_login_request(argv[1],argv[2],argv[3]) + "</llsd>\r\n\r\n";
			request.content().assign(llsd.begin(),llsd.end());

			request.header().content_type() 	= "application/xml+llsd";
			request.header().content_length() 	= boost::lexical_cast<String>(llsd.size());
			request.header().connection() 		= "close";

			std::cout << "Request looks like: " << std::endl;
			std::cout << request.header().request() << llsd;
			std::cout << std::endl;

			if(!ptr->async_request(request, on_received))
			{
				std::cout << "Request setup failed!" << std::endl;
				return 0;
			}
			
			std::cout << "Starting service..." << std::endl;
		}

		service.run();

		std::cout << "Service processed the queue. Request should have finished" << std::endl;
		logger::shutdown();
	}
	catch(std::exception const & e)
	{
		std::cout << "Exception caught: " << e.what() << std::endl << "Exception type: " << typeid(e).name();
	}
	return 0;
}
Example #7
0
static bool compare_nocase_breadth_first(const String& first, const String& second) {
    // Check "path depth" first
    unsigned firstPathDepth = std::count(first.begin(), first.end(), '/');
    unsigned secondPathDepth = std::count(second.begin(), second.end(), '/');
    if (firstPathDepth < secondPathDepth)
        return true;
    else if (firstPathDepth > secondPathDepth)
        return false;

    unsigned i = 0;
    while ((i < first.length()) && (i < second.length())) {
        if (tolower(first[i]) < tolower(second[i]))
            return true;
        else if (tolower(first[i]) > tolower(second[i]))
            return false;
        ++i;
    }

    if (first.length() < second.length())
        return true;
    else
        return false;
}
Example #8
0
Size findIdOfAminoAcid(const aas::String& name)
{
    for (Size i = 0; i < nEntries_aminoAcids; ++i) {
        if (fullNames[i] == name) {
            return i;
        }
    }
    // Cannot find full name. search case insensitive.
    String rhs = name;
    std::transform(rhs.begin(), rhs.end(), rhs.begin(), ::tolower);
    for (Size i = 0; i < nEntries_aminoAcids; ++i) {
        String lhs = fullNames[i];
        std::transform(lhs.begin(), lhs.end(), lhs.begin(), ::tolower);
        if (rhs == lhs) {
            return i;
        }
    }
    std::ostringstream os;
    os << "RawAminoAcidImpl::findIdOfAminoAcid(): Cannot find given name '";
    os << name;
    os << "' in standard list of amino acids.";
    aas_logic_error(os.str());
}
Example #9
0
	//-----------------------------------------------------------------------
	void DynLib::load()
	{
		// Log library load
		LogManager::getSingleton().logMessage("Loading library " + mName);

		String name = mName;
#if OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN
		if (name.find(".js") == String::npos)
			name += ".js";
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_NACL
		// dlopen() does not add .so to the filename, like windows does for .dll
		if (name.find(".so") == String::npos)
		{
			name += ".so.";
			name += StringConverter::toString(OGRE_VERSION_MAJOR) + ".";
			name += StringConverter::toString(OGRE_VERSION_MINOR) + ".";
			name += StringConverter::toString(OGRE_VERSION_PATCH);
		}
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
		// dlopen() does not add .dylib to the filename, like windows does for .dll
		if (name.substr(name.find_last_of(".") + 1) != "dylib")
			name += ".dylib";
#elif OGRE_PLATFORM == OGRE_PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WINRT
		// Although LoadLibraryEx will add .dll itself when you only specify the library name,
		// if you include a relative path then it does not. So, add it to be sure.
		if (name.substr(name.find_last_of(".") + 1) != "dll")
			name += ".dll";
#endif

#ifdef _UNICODE
		std::wstring wStr(name.begin(), name.end());
		mInst = (DYNLIB_HANDLE)DYNLIB_LOAD(wStr.c_str());
#else
		mInst = (DYNLIB_HANDLE)DYNLIB_LOAD(name.c_str());
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
		if (!mInst)
		{
			// Try again as a framework
			mInst = (DYNLIB_HANDLE)FRAMEWORK_LOAD(mName);
		}
#endif
		if (!mInst)
			OGRE_EXCEPT(
				Exception::ERR_INTERNAL_ERROR,
				"Could not load dynamic library " + mName +
				".  System Error: " + dynlibError(),
				"DynLib::load");
	}
void Document::loadFromCurrenttDir( const String& fileName_ )
{
	FRL_EXCEPT_GUARD();
	String currDir = io::fs::getCurrentDirectory();
	io::fs::addSlashToEndPath( currDir );
	fileName = currDir + fileName_;
	String buffer;
	loadFileToString( fileName, buffer );
	buffer.erase( std::remove_if( buffer.begin(), buffer.end(), private_::isCRLF ), buffer.end() ); // remove CRLF
	parseHeader( buffer );
	NodesList tmpMap = Parser::getSubNodes( buffer );
	if( tmpMap.size() > 1 )
		FRL_THROW_S_CLASS( Document::BrokenXML ); // must be one root node
	root = (*tmpMap.begin());
}
inline bool string_parse(
    String const& str
    , Iterator& first, Iterator const& last, Attribute& attr)
{
    Iterator i = first;
    typename String::const_iterator stri = str.begin();
    typename String::const_iterator str_last = str.end();

    for (; stri != str_last; ++stri, ++i)
        if (i == last || (*stri != *i))
            return false;
    spirit::traits::assign_to(first, i, attr);
    first = i;
    return true;
}
Example #12
0
    inline bool string_parse(
        String const& str
      , Iterator& first, Iterator const& last, Attribute& attr, CaseCompareFunc const& compare)
    {
        Iterator i = first;
        typename String::const_iterator stri = str.begin();
        typename String::const_iterator str_last = str.end();

        for (; stri != str_last; ++stri, ++i)
            if (i == last || (compare(*stri, *i) != 0))
                return false;
        x3::traits::move_to(first, i, attr);
        first = i;
        return true;
    }
Example #13
0
Size findIdOfAminoAcidThreeLetter(const aas::String& tlc)
{
    for (Size i = 0; i < nEntries_aminoAcids; ++i) {
        if (three_letter[i] == tlc) {
            return i;
        }
    }
    // Cannot find three letter code. search case insensitive.
    String rhs = tlc;
    std::transform(rhs.begin(), rhs.end(), rhs.begin(), ::tolower);
    for (Size i = 0; i < nEntries_aminoAcids; ++i) {
        String lhs = three_letter[i];
        std::transform(lhs.begin(), lhs.end(), lhs.begin(), ::tolower);
        if (rhs == lhs) {
            return i;
        }
    }
    std::ostringstream os;
    os
            << "RawAminoAcidImpl::findIdOfAminoAcidThreeLetter(): Cannot find given three letter code '";
    os << tlc;
    os << "' in standard list of amino acids.";
    aas_logic_error(os.str());
}
Example #14
0
void
reextendFileName(const String& in_rFileName,
                 const String& in_rNewExtension,
                 String&       out_rNewFileName)
{
   out_rNewFileName = in_rFileName;
   String::iterator itr;
   for (itr = out_rNewFileName.end(); itr != out_rNewFileName.begin(); --itr) {
      if (*itr == '.')
         break;
   }
   if (itr == out_rNewFileName.begin() ||
       (out_rNewFileName.end() - itr) < in_rNewExtension.length()) {
      // There was no extension, or not enough room for the new one...
      //
      char tmpBuf[512];
      strcpy(tmpBuf, out_rNewFileName.c_str());
      strcat(tmpBuf, in_rNewExtension.c_str());
      out_rNewFileName = tmpBuf;
   } else {
      char* pExt = itr;
      strcpy(pExt, in_rNewExtension.c_str());
   }
}
Example #15
0
    OutputIterator operator()(const String& str, OutputIterator dest, int level)
    {
        using json::generator_internal::encode_string;

        std::copy(TokenTraits::quote_token.cbegin(), TokenTraits::quote_token.cend(), dest);
        auto first = str.begin();
        auto last = str.end();
        const unsigned int options = (flags()&escape_solidus) ? generator_internal::string_encoder_base::EscapeSolidus : 0;
#if !defined (NDEBUG)
        int cvt_result =
#endif
            encode_string(first, last, string_encoding_type(),
                          dest, OutEncoding(),
                          options);
        assert(cvt_result == 0);
        return std::copy(TokenTraits::quote_token.cbegin(), TokenTraits::quote_token.cend(), dest);
    }
Example #16
0
bool int_parse( const String& s, bool Sign, sint8& n )
{
  if ( s.empty() ) return false;

  String::const_iterator it = s.begin();
  String::const_iterator hi = s.end();

  bool sign = !Sign;
  for ( ; it != hi; it++ ) {
    if ( ( *it == '+' || *it == '-' ) && ! sign ) { sign = true; continue; }
    if (! isdigit( *it ) ) return false;
  }

  n = atoi( s.c_str() );

  return true;
}
 void CompNovoIdentificationBase::permute_(String prefix, String s, set<String> & permutations)
 {
   if (s.size() <= 1)
   {
     permutations.insert(prefix + s);
   }
   else
   {
     for (String::Iterator p = s.begin(); p < s.end(); p++)
     {
       char c = *p;
       p = s.erase(p);
       permute_(prefix + c, s, permutations);
       s.insert(p, c);
     }
   }
 }
  AASequence CompNovoIdentificationBase::getModifiedAASequence_(const String & sequence)
  {
    AASequence seq;
    for (String::ConstIterator it = sequence.begin(); it != sequence.end(); ++it)
    {
      if (name_to_residue_.has(*it))
      {
        seq += name_to_residue_[*it];
      }
      else
      {
        seq += *it;
      }
    }

    return seq;
  }
 String QueryParseError::addEscapes(const String& str)
 {
     StringStream buffer;
     for (String::const_iterator ch = str.begin(); ch != str.end(); ++ch)
     {
         switch (*ch)
         {
             case L'\0':
                 continue;
             case L'\b':
                 buffer << L"\\b";
                 continue;
             case L'\t':
                 buffer << L"\\t";
                 continue;
             case L'\n':
                 buffer << L"\\n";
                 continue;
             case L'\f':
                 buffer << L"\\f";
                 continue;
             case L'\r':
                 buffer << L"\\r";
                 continue;
             case L'\"':
                 buffer << L"\\\"";
                 continue;
             case L'\'':
                 buffer << L"\\\'";
                 continue;
             case L'\\':
                 buffer << L"\\\\";
                 continue;
             default:
                 if (*ch < 0x20 || *ch > 0x7e)
                 {
                     String hexChar(L"0000" + StringUtils::toString(*ch, 16));
                     buffer << L"\\u" + hexChar.substr(hexChar.length() - 4);
                 }
                 else
                     buffer << *ch;
                 continue;
         }
     }
     return buffer.str();
 }
Example #20
0
        StringVector GetSystemPATH(const String& PATH)
        {
            StringVector Results;
            const Char8 Sep = GetPathSeparator();
            String OneEntry;

            for( String::const_iterator Current = PATH.begin() ; PATH.end()!=Current ; ++Current )
            {
                if(Sep==*Current) {
                    Results.push_back(OneEntry);
                    OneEntry.clear();
                }else{
                    OneEntry += *Current;
                }
            }
            return Results;
        }
//----------------------------------------------------------------------------//
RenderedString BasicRenderedStringParser::parse(const String& input_string,
                                                const Font* active_font,
                                                const ColourRect* active_colours)
{
    // first-time initialisation (due to issues with static creation order)
    if (!d_initialised)
        initialiseTagHandlers();

    initialiseDefaultState();

    // Override active font if necessary
    if (active_font)
        d_fontName = active_font->getName();

    // Override active font if necessary
    if (active_colours)
        d_colours = *active_colours;

    RenderedString rs;
    String curr_section, tag_string;

    for (String::const_iterator input_iter(input_string.begin());
         input_iter != input_string.end();
         /* no-op*/)
    {
        const bool found_tag = parse_section(input_iter, input_string.end(), '[', curr_section);
        appendRenderedText(rs, curr_section);

        if (!found_tag)
            return rs;

        if (!parse_section(input_iter, input_string.end(), ']', tag_string))
        {
            Logger::getSingleton().logEvent(
                "BasicRenderedStringParser::parse: Ignoring unterminated tag : [" +
                tag_string);

            return rs;
        }

        processControlString(rs, tag_string);
    }

    return rs;
}
Example #22
0
FileSystem::eCreateDirectoryResult FileSystem::CreateDirectory(const String & filePath, bool isRecursive)
{
    String path = SystemPathForFrameworkPath(filePath);
	if (!isRecursive)
	{
        return CreateExactDirectory(path);
	}

	std::replace(path.begin(), path.end(),'\\','/');
	Vector<String> tokens;
    Split(path, "/", tokens);
    
	String dir = "";

#if defined (__DAVAENGINE_WIN32__)
    if(0 < tokens.size() && 0 < tokens[0].length())
    {
        String::size_type pos = path.find(tokens[0]);
        if(String::npos != pos)
        {
            tokens[0] = path.substr(0, pos) + tokens[0];
        }
    }
#else //#if defined (__DAVAENGINE_WIN32__)
    size_t find = path.find(":");
    if(find == path.npos)
	{
        dir = "/";
    }
#endif //#if defined (__DAVAENGINE_WIN32__)
	
	for (size_t k = 0; k < tokens.size(); ++k)
	{
		dir += tokens[k] + "/";
        
        eCreateDirectoryResult ret = CreateExactDirectory(dir);
		if (k == tokens.size() - 1)
        {
            return ret;
        }
	}
	return DIRECTORY_CANT_CREATE;
}
Example #23
0
 bool is_floating_point(const String &s) {
   typedef typename String::const_iterator iter_type;
   iter_type i = s.begin();
   bool found_frac = false;
   for (;i < s.end(); ++i) {
     if (*i == '.') {
       if (found_frac) {
         return false;
       }
       else {
         found_frac = true;
       }
     }
     else if (*i < '0' || *i > '9') {
       return false;
     }
   }
   return true;
 }
Vector2 ObjectTitle::getTextDimensions(String text)
{
    Real charHeight = StringConverter::parseReal(font->getParameter("size"));
 
    Vector2 result(0, 0);
 
    for(String::iterator i = text.begin(); i < text.end(); i++)
    {   
        if (*i == 0x0020)
            result.x += font->getGlyphAspectRatio(0x0030);
        else
            result.x += font->getGlyphAspectRatio(*i);
    }
 
    result.x = (result.x * charHeight) / (float)camera->getViewport()->getActualWidth();
    result.y = charHeight / (float)camera->getViewport()->getActualHeight();
 
    return result;
}
Example #25
0
String Path::ReplaceExtension(String path, String newExt)
{
	newExt.TrimFront('.');

	// Remove everything in the extension and the dot
	size_t dotPos = path.find_last_of(".");
	if(dotPos != -1)
	{
		path.erase(path.begin() + dotPos, path.end());
	}

	if(newExt.empty())
		return path;

	path.push_back('.');
	path += newExt;

	return path;
}
Example #26
0
//! Utility function to escape a string using %XML entities, such that it's suitable for representing an attribute value.
String XML::escape( String const &str )
{
  String s;
  for ( String::const_iterator i = str.begin(); i != str.end(); ++i ) {
    unsigned char c = *i;
    if ( (c < 32) && (c != 9) && (c != 10) && (c != 13) )
      continue;

         if ( c == '&' )  s += "&amp;";
    else if ( c == '<' )  s += "&lt;";
    else if ( c == '\'' ) s += "&apos;";
    else if ( (c < 32) || (c > 127) || (c == 39) )
      s += String::format( "&#%i;", c );
    else
      s += c;
  }

  return( s );
}
Example #27
0
/**
This function sets the section header fields.
@internalComponent
@released
@return Error status
@param aSectionIndex The index of the section
@param aSectionName The name of the section
@param aType The type of the section
@param aEntSz The size of each entry of the section
@param aSectionSize The size of the section
@param aLink The section this section is linked to
@param aInfo Extra information. Depends on the section type of this section.
@param aAddrAlign The address alignment of this section.
@param aFlags Section flags
@param aAddr The address of this section in memory(Here it remains 0)
*/
void ElfProducer::SetSectionFields(PLUINT32 aSectionIndex, char* aSectionName, PLUINT32 aType, \
								   PLUINT32 aEntSz, PLUINT32 aSectionSize, PLUINT32 aLink, \
								   PLUINT32 aInfo, PLUINT32 aAddrAlign, PLUINT32 aFlags, \
								   PLUINT32 aAddr)
{
	String aSecName = aSectionName;

	iSections[aSectionIndex].sh_name			= iDSOSectionNames.size();
	iDSOSectionNames.insert(iDSOSectionNames.end(), aSecName.begin(), aSecName.end());
	iDSOSectionNames.insert(iDSOSectionNames.end(), 0);
	
	iSections[aSectionIndex].sh_type			= aType;
	iSections[aSectionIndex].sh_entsize		= aEntSz;
	iSections[aSectionIndex].sh_size			= aSectionSize;
	iSections[aSectionIndex].sh_link			= aLink;
	iSections[aSectionIndex].sh_flags		= aFlags;
	iSections[aSectionIndex].sh_addralign	= aAddrAlign;
	iSections[aSectionIndex].sh_info			= aInfo;
	iSections[aSectionIndex].sh_addr			= aAddr;
}
Example #28
0
  void
  UniqueIdInterface::setUniqueId(const String & rhs)
  {
    clearUniqueId();

    String::size_type last_underscore = rhs.rfind('_');
    String s = rhs.substr(last_underscore + 1);

    for (String::const_iterator s_i = s.begin(); s_i < s.end(); ++s_i)
    {
      int i = (*s_i - '0');
      if (i < 0 || i > 9)
      {
        clearUniqueId();
        return;
      }
      unique_id_ = 10 * unique_id_ + i;
    }

  }
Example #29
0
// Construct an NTuple from a string of 0's and 1's
NTuple::NTuple( String bit_string )
	: mTuple( GAParams::NumVars() )
{
//	std::cout << bit_string << std::endl;
	size_t i = 0;
	String::const_iterator iter = bit_string.begin();
	while( iter != bit_string.end( ) )
	{
		if( *iter == '1' )
		{
			mTuple.Set(i);
		} 
		// Ignore all but 0's and 1's
		if( *iter == '1'|| *iter == '0' )
		{
			++i;
		}
		++iter;
	}
}
Example #30
0
		/// <summary>
		/// 正規表現に一致する全てのマッチを返します。
		/// </summary>
		/// <param name="input">
		/// 対象の文字列
		/// </param>
		/// <param name="regex">
		/// 検索する正規表現
		/// </param>
		/// <returns>
		/// マッチの一覧
		/// </returns>
		inline Array<Match> Search(const String& input, const String& regex)
		{
			const std::wregex reg(regex.str());

			auto begin = input.begin();
			const auto end = input.end();

			std::wsmatch match;

			Array<Match> results;

			while (std::regex_search(begin, end, match, reg))
			{
				results.emplace_back(match);

				begin = match[0].second;
			}

			return results;
		}