Example #1
0
bool Desktop::OnCompleteCommand(const string_t &cmd, int &pos, string_t &result)
{
    assert(pos >= 0);
    lua_getglobal(g_env.L, "autocomplete");
    if( lua_isnil(g_env.L, -1) )
    {
        lua_pop(g_env.L, 1);
        GetConsole().WriteLine(1, "There was no autocomplete module loaded");
        return false;
    }
    lua_pushlstring(g_env.L, cmd.substr(0, pos).c_str(), pos);
    HRESULT hr = S_OK;
    if( lua_pcall(g_env.L, 1, 1, 0) )
    {
        GetConsole().WriteLine(1, lua_tostring(g_env.L, -1));
    }
    else
    {
        const char *str = lua_tostring(g_env.L, -1);
        string_t insert = str ? str : "";

        result = cmd.substr(0, pos) + insert + cmd.substr(pos);
        pos += insert.length();

        if( g_client && !g_client->IsLocal() && !result.empty() && result[0] != '/' )
        {
            result = string_t("/") + result;
            ++pos;
        }
    }
    lua_pop(g_env.L, 1); // pop result or error message
    return true;
}
Example #2
0
bool Parser::IsDashCharacter(const string_t& str) {
  if (str.size() != 1)
    return false;

  auto result = std::find(kDashes.begin(), kDashes.end(), str.front());
  return result != kDashes.end();
}
Example #3
0
CServerMessagePacket::CServerMessagePacket(const string_t message, int8 language, int32 timestamp, int32 message_offset)
{
    this->type = 0x4D;
    this->size = 0x0E;

    WBUFB(data, (0x04) ) = message_offset == 0 ? 1 : 2;
    WBUFB(data, (0x05) ) = 1;
    WBUFB(data, (0x06) ) = 1;
    WBUFB(data, (0x07) ) = language;
    WBUFL(data, (0x08) ) = timestamp == 0 ? time(0) : timestamp;
    WBUFL(data, (0x0C) ) = 0; // Message Length.. (Total)
    WBUFL(data, (0x10) ) = 0; // Message Offset..
    WBUFL(data, (0x14) ) = 0; // Message Length..

    // Ensure we have a message and the requested offset is not outside of the bounds..
    if (message.length() > 0 && message.length() > message_offset)
    {
        int32 msgLength = message.length();
        int32 sndLength = (msgLength - message_offset) > 236 ? 236 : (msgLength - message_offset);

        WBUFL(data, (0x0C) ) = message.length(); // Message Length.. (Total)
        WBUFL(data, (0x10) ) = message_offset;   // Message Offset..
        WBUFL(data, (0x14) ) = sndLength;        // Message Length..

        memcpy((data + (0x18)) , message.c_str() + message_offset, sndLength);

        int32 textSize = sndLength + sndLength % 2;
        this->size = ((((0x14 + textSize) + 4) >> 1) & 0xFE);
    }
Example #4
0
// From CamelCase to snake_case
std::string CamelCase(const string_t & name)
{
    // Replace '_' + a lowercase letter with an upper case letter
    string_t str;
    str.reserve(name.size());
    for (size_t i = 0; i < name.size(); ++i)
    {
        if (i == 0 || name[i] == puzT('_'))
        {
            if (i > 0)
                ++i;
            if (i < name.size())
            {
            #if PUZ_UNICODE
                if (::iswlower(name[i]))
                    str.push_back(::towupper(name[i]));
            #else // ! PUZ_UNICODE
                if (::islower(name[i]))
                    str.push_back(::toupper(name[i]));
            #endif // PUZ_UNICODE/! PUZ_UNICODE
                else // Not lower case: so push both the underscore and letter
                {
                    if (i > 0)
                        str.push_back(name[i-1]);
                    str.push_back(name[i]);
                }
            }
            else if (i > 0) // At the end of the string: push the underscore
                str.push_back(name[i-1]);
        }
        else // Not a hypen: push the letter
            str.push_back(name[i]);
    }
    return encode_utf8(str);
}
Example #5
0
bool Parser::MatchTypeAndEpisodePattern(const string_t& word, Token& token) {
  size_t number_begin = FindNumberInString(word);
  auto prefix = word.substr(0, number_begin);

  ElementCategory category = kElementAnimeType;
  KeywordOptions options;

  if (keyword_manager.Find(keyword_manager.Normalize(prefix),
                           category, options)) {
    elements_.insert(kElementAnimeType, prefix);
    auto number = word.substr(number_begin);
    if (MatchEpisodePatterns(number, token) ||
        SetEpisodeNumber(number, token, true)) {
      auto it = std::find(tokens_.begin(), tokens_.end(), token);
      if (it != tokens_.end()) {
        // Split token (we do this last in order to avoid invalidating our
        // token reference earlier)
        token.content = number;
        tokens_.insert(it, Token(options.identifiable ? kIdentifier : kUnknown,
                                 prefix, token.enclosed));
      }
      return true;
    }
  }

  return false;
}
Example #6
0
bool Parser::IsResolution(const string_t& str) {
  // Using a regex such as "\\d{3,4}(p|(x\\d{3,4}))$" would be more elegant,
  // but it's much slower (e.g. 2.4ms -> 24.9ms).

  const size_t min_width_size = 3;
  const size_t min_height_size = 3;

  // *###x###*
  if (str.size() >= min_width_size + 1 + min_height_size) {
    size_t pos = str.find_first_of(L"xX\u00D7");  // multiplication sign
    if (pos != str.npos &&
        pos >= min_width_size &&
        pos <= str.size() - (min_height_size + 1)) {
      for (size_t i = 0; i < str.size(); i++)
        if (i != pos && !IsNumericChar(str.at(i)))
          return false;
      return true;
    }

  // *###p
  } else if (str.size() >= min_height_size + 1) {
    if (str.back() == L'p' || str.back() == L'P') {
      for (size_t i = 0; i < str.size() - 1; i++)
        if (!IsNumericChar(str.at(i)))
          return false;
      return true;
    }
  }

  return false;
}
Example #7
0
void Tokenizer::TokenizeByDelimiters(bool enclosed, const TokenRange& range) {
  const string_t delimiters = GetDelimiters(range);

  if (delimiters.empty()) {
    AddToken(kUnknown, enclosed, range);
    return;
  }

  auto char_begin = filename_.begin() + range.offset;
  const auto char_end = char_begin + range.size;
  auto current_char = char_begin;

  while (current_char != char_end) {
    current_char = std::find_first_of(current_char, char_end,
                                      delimiters.begin(), delimiters.end());

    const TokenRange subrange(std::distance(filename_.begin(), char_begin),
                              std::distance(char_begin, current_char));

    if (subrange.size > 0)  // Found unknown token
      AddToken(kUnknown, enclosed, subrange);

    if (current_char != char_end) {  // Found delimiter
      AddToken(kDelimiter, enclosed,
               TokenRange(subrange.offset + subrange.size, 1));
      char_begin = ++current_char;
    }
  }

  ValidateDelimiterTokens();
}
// Creates a string of neighboring edge pixels.
inline
void
linking_procedure(string_t &string, unsigned char *binary_image, const size_t image_width, const size_t image_height, const int x_ref, const int y_ref, const double half_width, const double half_height)
{
	/* Leandro A. F. Fernandes, Manuel M. Oliveira
	 * Real-time line detection through an improved Hough transform voting scheme
	 * Pattern Recognition (PR), Elsevier, 41:1, 2008, 299-314.
	 *
	 * Algorithm 5
	 */

	int x, y;

	string.clear();
	
	// Find and add feature pixels to the end of the string.
	x = x_ref;
	y = y_ref;
	do
	{
		pixel_t &p = string.push_back();
		
		p.x_index = x;
		p.y_index = y;

		p.x = x - half_width;
		p.y = y - half_height;

		binary_image[y*image_width+x] = 0;
	}
	while (next( x, y, binary_image, image_width, image_height ));

	pixel_t temp;
	for (size_t i=0, j=string.size()-1; i<j; ++i, --j)
	{
		temp = string[i];
		string[i] = string[j];
		string[j] = temp;
	}

	// Find and add feature pixels to the begin of the string.
	x = x_ref;
	y = y_ref;
	if (next( x, y, binary_image, image_width, image_height ))
	{
		do
		{
			pixel_t &p = string.push_back();

			p.x_index = x;
			p.y_index = y;

			p.x = x - half_width;
			p.y = y - half_height;

			binary_image[y*image_width+x] = 0;
		}
		while (next( x, y, binary_image, image_width, image_height ));
	}
}
Example #9
0
    virtual bool open_file
    (io::read::file& file, const string_t& line,
     const string_t& name, bool mode_is_binary = false) {
        size_t length;

        if ((line.has_chars(length))) {
#if defined(__GNUC__)
            char_t chars[length + 3];
#else // defined(__GNUC__)
            nadir::arrayt<char_t> a(length + 3);
            char_t* chars = a.elements();
#endif // defined(__GNUC__)

            if ((file.open(name.chars(), (mode_is_binary)
                ?(file.mode_read_binary()):(file.mode_read())))) {
                if (!((length + 2) != (file.read(chars, length + 2)))) {
                    if (!(line.compare(chars, length))) {
                        if (!((cr_ != chars[length]) || (lf_ != chars[length+1]))) {
                            return true;
                        }
                    }
                }
                file.close();
            }
        }
        return false;
    }
Example #10
0
void KeywordManager::Peek(const string_t& filename,
                          const TokenRange& range,
                          Elements& elements,
                          std::vector<TokenRange>& preidentified_tokens) const {
  typedef std::pair<ElementCategory, std::vector<string_t>> entry_t;
  static const std::vector<entry_t> entries{
    {kElementAudioTerm, {L"Dual Audio"}},
    {kElementVideoTerm, {L"H264", L"H.264", L"h264", L"h.264"}},
    {kElementVideoResolution, {L"480p", L"720p", L"1080p"}},
    {kElementSource, {L"Blu-Ray"}}
  };

  auto it_begin = filename.begin() + range.offset;
  auto it_end = it_begin + range.size;

  for (const auto& entry : entries) {
    for (const auto& keyword : entry.second) {
      auto it = std::search(it_begin, it_end, keyword.begin(), keyword.end());
      if (it != it_end) {
        auto offset = it - filename.begin();
        elements.insert(entry.first, keyword);
        preidentified_tokens.push_back(TokenRange(offset, keyword.size()));
      }
    }
  }
}
Example #11
0
void statement::use_value(int pos, string_t const& value, bool make_copy)
{
	s_.check_error( aux::select(::sqlite3_bind_text, ::sqlite3_bind_text16)
		(impl_, pos, value.empty()? 0 : value.c_str(), 
		static_cast<int>(value.size() * sizeof(char_t)), make_copy? SQLITE_TRANSIENT : SQLITE_STATIC)
	);
}
Example #12
0
file_t::file_t(char const *name, string_t const &header) :
	ref_cnt(0), fd(-1), used(false), id() {

	if(config::check)
		return;

	fd = ::open(name, O_WRONLY | O_APPEND | O_CREAT, 0644);
	if(fd < 0)
		throw exception_sys_t(log::error, errno, "open (%s): %m", name);

	fd_guard_t guard(fd);

	id = id_t(fd, used);
	if(!id)
		throw exception_sys_t(log::error, errno, "fstat (%s): %m", name);

	if(::flock(fd, LOCK_SH | LOCK_NB) < 0)
		throw exception_sys_t(log::error, errno, "flock (%s): %m", name);

	if(header) {
		if(::write(fd, header.ptr(), header.size()) < 0)
			throw exception_sys_t(log::error, errno, "write (%s): %m", name);
	}

	guard.relax();
}
Example #13
0
void cmdline_t::add(
        const string_t& short_name, const string_t& name, const string_t& description,
        const string_t& default_value) const
{
        if (    name.empty() ||
                nano::starts_with(name, "-") ||
                nano::starts_with(name, "--"))
        {
                log_critical("cmdline: invalid option name [" + name + "]");
        }

        if (    !short_name.empty() &&
                (short_name.size() != 1 || short_name[0] == '-'))
        {
                log_critical("cmdline: invalid short option name [" + short_name + "]");
        }

        if (    m_impl->find(name) != m_impl->m_options.end())
        {
                log_critical("cmdline: duplicated option [" + name + "]");
        }

        if (    !short_name.empty() &&
                m_impl->find(short_name) != m_impl->m_options.end())
        {
                log_critical("cmdline: duplicated option [" + short_name + "]");
        }

        m_impl->m_options.emplace_back(short_name, name, description, default_value);
}
static void test_1_01()
{
    PAN_CHAR_T      hostname[1000];
    const string_t  hid = pan_get_hid_();

    { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(hostname); ++i)
    {
        ::memset(&hostname[0], 0, sizeof(hostname));

        const size_t len = pantheios::getHostName(&hostname[0], i);

        if(len == i)
        {
            // The function did not have enough space to write in, so it
            // will return the length passed to it ...
            XTESTS_TEST_INTEGER_EQUAL(i, len);
            // ... and will not have written anything to the file
            XTESTS_TEST_STRING_EQUAL(PANTHEIOS_LITERAL_STRING(""), hostname);
        }
        else
        {
            // The function had enough space, so it will return the length
            // of the intended hostname ...
            XTESTS_TEST_INTEGER_EQUAL(hid.size(), len);
            // ... and will have written the hostname
            XTESTS_TEST_STRING_EQUAL(hid, hostname);
        }
    }}
}
Example #15
0
    bool containsKeyword (string_t keyword, value_t& value)
    {
        typename Entry::childen_t::iterator current;
        typename Entry::childen_t::iterator next;

        current = mRoot.mChildren.find (std::tolower (*keyword.begin(), mLocale));
        if (current == mRoot.mChildren.end())
            return false;
        else if (current->second.mKeyword.size() && Misc::StringUtils::ciEqual(current->second.mKeyword, keyword))
        {
            value = current->second.mValue;
            return true;
        }

        for (Point i = ++keyword.begin(); i != keyword.end(); ++i)
        {
            next = current->second.mChildren.find(std::tolower (*i, mLocale));
            if (next == current->second.mChildren.end())
                return false;
            if (Misc::StringUtils::ciEqual(next->second.mKeyword, keyword))
            {
                value = next->second.mValue;
                return true;
            }
            current = next;
        }
        return false;
    }
Example #16
0
	bool
	build_shmem( string_t const& name, size_t const size, shmem_t & shmem, shmem_region_t & shmem_region, T*& p ) {
		//
		bool const create = ( size > 0 );
		if ( create ) {
			shmem = shmem_t( 
				new boost::interprocess::windows_shared_memory( 
						boost::interprocess::create_only,
						name.c_str(),
						boost::interprocess::read_write,
						size )
					);
		} else {
			shmem = shmem_t( 
						new boost::interprocess::windows_shared_memory(
						boost::interprocess::open_only,
						name.c_str(),
						boost::interprocess::read_write )
					);
		}
		shmem_region = shmem_region_t(
							new boost::interprocess::mapped_region(
								*(shmem.get()),
								boost::interprocess::read_write )
						);
		//
		p = static_cast< T* >( shmem_region->get_address() );
		if ( create && p ) {
			memset( p, 0, size );
		}
		return true;
	}
Example #17
0
//---------------------------------------------------------------------------
void WordMacros::Replace(const string_t& text, const string_t& repl)
{
  // обходим проблему текста длинее 255 символов
  const size_t MAX_REPL_LEN = 200;
  if (repl.size() > MAX_REPL_LEN)
  {
    string_t newText;
    std::vector<string_t> rs;
    for (size_t i = 0; i < repl.size(); i+= MAX_REPL_LEN)
    {
      newText += text + aux::itow(rs.size());
      rs.push_back(repl.subString(i, MAX_REPL_LEN));
    }
    Replace(text, newText);
    for (size_t i = 0; i < rs.size(); ++i)
      Replace(text + aux::itow(i), rs[i]);
    return;
  }

  m_Macros += "With Selection.Find \n";
  m_Macros += "   .ClearFormatting \n";
  m_Macros += "   .Replacement.ClearFormatting \n";
  m_Macros += "   .Text = \"" + text +"\" \n";
  m_Macros += "   .Replacement.Text = \"" + repl +"\" \n";
  m_Macros += "   .Execute Replace:=wdReplaceAll \n";
  m_Macros += "End With \n";
  IsLarge();
}
Example #18
0
bool MusicDecoder::splitComment(
    const char* comment,
    unsigned int size,
    string_t& field,
    string_t& value)
{
#ifdef STRING_T_IS_SF_STRING
  sf::String str=sf::String::fromUtf8(comment, &(comment[size]));
  size_t split=str.find(sf::String("="));
  if (split==sf::String::InvalidPos){
    return false;
  } else {
    field=str.substring(0,split);
    value=str.substring(split+1);
    sf::String::Iterator it;
    for (it=field.begin(); it !=field.end(); it++)
    {
      *it=toupper(*it);
    }

    //std::cout << "field " << field.toAnsiString() << "=" << value.toAnsiString() << std::endl;
    return true;
  }
#else
  return false;
#endif
}
Example #19
0
bool Anitomy::RemoveExtensionFromFilename(string_t& filename,
                                          string_t& extension) {
  const size_t position = filename.find_last_of(L'.');

  if (position == string_t::npos)
    return false;

  extension = filename.substr(position + 1);

  const size_t max_length = 4;
  if (extension.length() > max_length)
    return false;

  if (!IsAlphanumericString(extension))
    return false;

  // TODO: Add an option for this
  auto keyword = StringToUpperCopy(extension);
  if (!keyword_manager.Find(kElementFileExtension, keyword))
    return false;

  filename.resize(position);

  return true;
}
Example #20
0
void FtpHelper::UploadFile(string_t ftpAddr, string_t fileName)
{
	url addr(ftpAddr);
	HINTERNET hInternet;
	HINTERNET hFtpSession;
	hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
	if (hInternet == NULL)
	{
		return;
	}
	else
	{		
		auto user = addr.user_.empty() ? string_t(L"Anonymous") : addr.user_;
		auto passw = addr.passw_.empty() ? string_t(L"Anonymous") : addr.passw_;

		hFtpSession = InternetConnect(hInternet, addr.host_.c_str(), INTERNET_DEFAULT_FTP_PORT, user.c_str(), passw.c_str(), INTERNET_SERVICE_FTP, 0, 0);
		if (hFtpSession == NULL)
		{
			return;
		}
		else
		{
			auto filepart = string_t(PathFindFileName(fileName.c_str()));
			if (!FtpPutFile(hFtpSession, fileName.c_str(), addr.path_.c_str(), FTP_TRANSFER_TYPE_BINARY, INTERNET_FLAG_PASSIVE))
			{
				return;
			}
		}
	}

}
Example #21
0
//---------------------------------------------------------------------------
string_t r::to_str_date(string_t sqlDate, string_t suffix /* = L"" */)
{
  static string_t mounthNames[12]={ "¤нвар¤", "феврал¤", "марта", "апрел¤", "ма¤", "июн¤", "июл¤", "августа", "сент¤бр¤", "окт¤бр¤", "но¤бр¤", "декабр¤"};
  string_t res = "";
  try
  {
    // число 
    res += sqlDate.subString(8,2);
    if (res.size() == 1) 
      res = "0" + res;
    res += " ";
    // мес¤ц 
    int mNum = (sqlDate.subString(5, 2).toInt()-1) % 12;
    if (mNum < 0)
      return "<невалидна¤ дата!>";
    res += mounthNames[mNum] + " ";
    // год
    res += sqlDate.subString(0,4);
    if (suffix.size()) 
      res += L" " + suffix;
  }
  catch(...)
  {
    return "<невалидна¤ дата!>";
  }
  return res;
}
Example #22
0
void statement::prepare()
{
	try
	{
		typedef meta::if_<sizeof(char_t) == sizeof(utf8_char), char const*, void const*>::type tail_type;
		char_t const* tail;
		string_t const sql = q_.sql();
		s_.check_error(
			aux::select(::sqlite3_prepare, ::sqlite3_prepare16)(s_.impl_, sql.c_str(),
				static_cast<int>(sql.size() * sizeof(char_t)),
				&impl_, reinterpret_cast<tail_type*>(&tail)) );
		if ( tail && *tail )
		{
			throw multi_stmt_not_supported();
		}

		// bind into binders
		std::accumulate(q_.intos().begin(), q_.intos().end(), 0, bind(*this));
		// bind use binders
		std::accumulate(q_.uses().begin(), q_.uses().end(), 1, bind(*this));
	}
	catch(std::exception const&)
	{
		// statement stays not prepared
		finalize(false);
		throw;
	}
}
Example #23
0
void KeywordManager::Peek(const string_t& filename,
                          const TokenRange& range,
                          Elements& elements,
                          std::vector<TokenRange>& preidentified_tokens) const {
  typedef std::pair<ElementCategory, std::vector<string_t>> entry_t;
  static /*const*/ std::vector<entry_t> entries;
  { ElementCategory c = kElementAudioTerm;       const char_t* k[] = {L"Dual Audio"}; entry_t e; e.first = c; e.second.assign(k, k + _countof(k)); entries.push_back(e); }
  { ElementCategory c = kElementVideoTerm;       const char_t* k[] = {L"H264", L"H.264", L"h264", L"h.264"}; entry_t e; e.first = c; e.second.assign(k, k + _countof(k)); entries.push_back(e); }
  { ElementCategory c = kElementVideoResolution; const char_t* k[] = {L"480p", L"720p", L"1080p"}; entry_t e; e.first = c; e.second.assign(k, k + _countof(k)); entries.push_back(e); }
  { ElementCategory c = kElementSource;          const char_t* k[] = {L"Blu-Ray"}; entry_t e; e.first = c; e.second.assign(k, k + _countof(k)); entries.push_back(e); }

  string_t::const_iterator it_begin = filename.begin() + range.offset;
  string_t::const_iterator it_end = it_begin + range.size;

  for(std::vector<entry_t>::const_iterator entry = entries.begin(); entry != entries.end(); ++entry) {
    for(std::vector<string_t>::const_iterator keyword = entry->second.begin(); keyword != entry->second.end(); ++keyword) {
      string_t::const_iterator it = std::search(it_begin, it_end, keyword->begin(), keyword->end());
      if (it != it_end) {
        size_t offset = it - filename.begin();
        elements.insert(entry->first, *keyword);
        preidentified_tokens.push_back(TokenRange(offset, keyword->size()));
      }
    }
  }
}
Example #24
0
    void cUpdateChecker::_OnTextContentReceived(const std::string& sContent)
    {
      LOG<<"cUpdateChecker::_OnTextContentReceived"<<std::endl;

      // Read the xml document
      spitfire::xml::reader reader;
      spitfire::document::cDocument document;

      spitfire::util::cProcessInterfaceVoid interface;
      spitfire::util::PROCESS_RESULT result = reader.ReadFromString(interface, document, sContent);
      if (result != spitfire::util::PROCESS_RESULT::COMPLETE) {
        LOG<<"cUpdateChecker::_OnTextContentReceived ReadFromString failed for string \""<<sContent<<"\", returning"<<std::endl;
        return;
      }

      //<latest>
      //  <linux>
      //    <version>0.8</version>
      //    <download>http://chris.iluo.net/projects/medusa/medusa.tar.gz</download>
      //    <page>http://chris.iluo.net/projects/medusa/</page>
      //  </linux>
      //</latest>

      spitfire::document::cNode::const_iterator iterLatest(document);
      if (!iterLatest.IsValid()) return;

      iterLatest.FindChild("latest");
      if (!iterLatest.IsValid()) return;

      spitfire::document::cNode::const_iterator iterPlatform(iterLatest);
      if (!iterPlatform.IsValid()) return;

      iterPlatform.FindChild("linux");
      if (!iterPlatform.IsValid()) return;

      // Get the version
      const string_t sVersion = GetContentOfChildNode(iterPlatform, "version");
      if (sVersion.empty()) {
        LOG<<"cUpdateChecker::_OnTextContentReceived Could not find version node or content, returning"<<std::endl;
        return;
      }

      spitfire::string::cStringParser sp(sVersion);
      string_t sMajorVersion;
      sp.GetToStringAndSkip(".", sMajorVersion);
      const string_t sMinorVersion = sp.GetToEnd();
      const int iMajorVersion = spitfire::string::ToUnsignedInt(sMajorVersion);
      const int iMinorVersion = spitfire::string::ToUnsignedInt(sMinorVersion);


      // Get the page
      const string_t sDownloadPage = GetContentOfChildNode(iterPlatform, "page");
      if (sDownloadPage.empty()) {
        LOG<<"cUpdateChecker::_OnTextContentReceived Could not find page node or content, returning"<<std::endl;
        return;
      }

      // Notify the handler
      handler.OnNewVersionFound(iMajorVersion, iMinorVersion, sDownloadPage);
    }
Example #25
0
	string_t CFileSystem::GetFileExtension( const string_t& fileName ) {
		string_t::size_type dot = fileName.find_last_of( '.' );

		if ( dot == std::string::npos) 
			return string_t( "" );

		return string_t( fileName.begin() + dot + 1, fileName.end() );
	}
Example #26
0
// ugly function #1
static bool mime_type_need_charset(string_t const &mtype) {
	char const *p = mtype.ptr();

	return (
		mtype.size() >= 5 &&
		p[0] == 't' &&  p[1] == 'e' && p[2] == 'x' &&  p[3] == 't' && p[4] == '/'
	);
}
void CPointBonusMapsAccessor::InputUnlock( inputdata_t& inputdata )
{
#if 0
	if ( m_pGameUI )
	{
		m_pGameUI->BonusMapUnlock( m_String_tFileName.ToCStr(), m_String_tMapName.ToCStr() );
	}
#endif
}
Example #28
0
  string_t cImageCacheManager::GetOrCreateThumbnailForImageFile(const string_t& sImageFilePath, IMAGE_SIZE imageSize)
  {
    LOG<<"cImageCacheManager::GetOrCreateThumbnailForImageFile \""<<sImageFilePath<<"\""<<std::endl;

    if (!IsConvertInstalled()) {
      LOG<<"cImageCacheManager::GetOrCreateThumbnailForImageFile convert is not installed, returning \"\""<<std::endl;
      return TEXT("");
    }

    spitfire::algorithm::cMD5 md5;
    md5.CalculateForFile(sImageFilePath);

    const string_t sCacheFolder = GetCacheFolderPath();

    string_t sFileJPG = TEXT("full.jpg");
    size_t width = 0;
    size_t height = 0;

    switch (imageSize) {
      case IMAGE_SIZE::THUMBNAIL: {
        sFileJPG = TEXT("thumbnail.jpg");
        width = 200;
        height = 200;
        break;
      }
    }

    const string_t sFilePathJPG = spitfire::filesystem::MakeFilePath(sCacheFolder, md5.GetResultFormatted() + TEXT("_") + sFileJPG);
    if (spitfire::filesystem::FileExists(sFilePathJPG)) return sFilePathJPG;

    const string_t sFolderJPG = spitfire::filesystem::GetFolder(sFilePathJPG);

    ostringstream_t o;
    o<<"\""<<GetConvertPath()<<"\" \""<<sImageFilePath<<"\"";
    if ((width != 0) && (height != 0)) o<<" -resize "<<width<<"x"<<height;
    o<<" -auto-orient \""<<sFilePathJPG<<"\"";
    const string_t sCommandLine = o.str();
    //LOG<<"cImageCacheManager::GetOrCreateThumbnailForImageFile Running command line \""<<sCommandLine<<"\""<<std::endl;
    #ifdef __WIN__
    RunCommandLine(sCommandLine);
    #else
    const int iResult = system(sCommandLine.c_str());
    if (iResult != 0) {
      LOG<<"cImageCacheManager::GetOrCreateThumbnailForImageFile convert returned "<<iResult<<" for \""<<sCommandLine<<"\", returning \"\""<<std::endl;
      return TEXT("");
    }
    #endif

    if (!spitfire::filesystem::FileExists(sFilePathJPG)) {
      LOG<<"cImageCacheManager::GetOrCreateThumbnailForImageFile Failed to create the thumbnail image \""<<sFilePathJPG<<"\", returning \"\""<<std::endl;
      return TEXT("");
    }

    return sFilePathJPG;
  }
Example #29
0
void pal::readdir(const string_t& path, const string_t& pattern, std::vector<pal::string_t>* list)
{
    assert(list != nullptr);

    std::vector<pal::string_t>& files = *list;

    auto dir = opendir(path.c_str());
    if (dir != nullptr)
    {
        struct dirent* entry = nullptr;
        while ((entry = readdir(dir)) != nullptr)
        {
            if (fnmatch(pattern.c_str(), entry->d_name, FNM_PATHNAME) != 0)
            {
                continue;
            }
             
            // We are interested in files only
            switch (entry->d_type)
            {
            case DT_DIR:
            case DT_REG:
                break;

            // Handle symlinks and file systems that do not support d_type
            case DT_LNK:
            case DT_UNKNOWN:
                {
                    std::string fullFilename;

                    fullFilename.append(path);
                    fullFilename.push_back(DIR_SEPARATOR);
                    fullFilename.append(entry->d_name);

                    struct stat sb;
                    if (stat(fullFilename.c_str(), &sb) == -1)
                    {
                        continue;
                    }

                    if (!S_ISREG(sb.st_mode) && !S_ISDIR(sb.st_mode))
                    {
                        continue;
                    }
                }
                break;

            default:
                continue;
            }

            files.push_back(pal::string_t(entry->d_name));
        }
    }
}
	real_t string_to_real_cast(string_t const& str)
	{
		typedef boost::spirit::qi::real_parser<real_t, boost::spirit::qi::real_policies<real_t>> real_parser_t;

		real_t value(0.);

		if (!boost::spirit::qi::parse(str.begin(), str.end(), real_parser_t(), value))
			_cast_is_failed(str);

		return value;
	}