Пример #1
0
String Map::GetVisibilityAsText() {

	String visDataAsText = "";

	visDataAsText.push_back('\n');

	for (int y = m_size.y - 1; y >= 0; y--) {
		for (int x = 0; x < m_size.x; x++) {
			Tile* tile = GetTileAtLocation(IntVector2(x, y));


			if (tile->IsVisible()) {
				visDataAsText.push_back('*');
			}
			else if (tile->IsExplored()) {
				visDataAsText.push_back('.');
			}
			else {
				visDataAsText.push_back('#');
			}
		}

		visDataAsText.push_back('\n');
	}

	return visDataAsText;
}
Пример #2
0
/*static*/ void URI::urlDecode(const String &url, String& ret )
{
	for (const char *s = url.c_str(); *s != '\0'; ++s) {
		if (*s != '%') {
			ret.push_back(*s);
			continue;
		}
			
		unsigned int c1 = (unsigned char)*++s;
		if (c1 >= (unsigned char)'0' && c1 <= (unsigned char)'9')
			c1 = c1 - (unsigned char)'0';
		else if (c1 >= (unsigned char)'a' && c1 <= (unsigned char)'f')
			c1 = c1 - (unsigned char)'a' + 10;
		else if (c1 >= (unsigned char)'A' && c1 <= (unsigned char)'F')
			c1 = c1 - (unsigned char)'A' + 10;
		else
			break;
		unsigned int c2 = (unsigned char)*++s;
		if (c2 >= (unsigned char)'0' && c2 <= (unsigned char)'9')
			c2 = c2 - (unsigned char)'0';
		else if (c2 >= (unsigned char)'a' && c2 <= (unsigned char)'f')
			c2 = c2 - (unsigned char)'a' + 10;
		else if (c2 >= (unsigned char)'A' && c2 <= (unsigned char)'F')
			c2 = c2 - (unsigned char)'A' + 10;
		else
			break;
			
		char c = (char)((c1 << 4) | c2);
		ret.push_back(c);
	}
}
Пример #3
0
String RulePrivate::quoteEscapeString(const String& value)
{
    String result;
    result.push_back('"');
    result.append(Rule::escapeString(value));
    result.push_back('"');
    return result;
}
Пример #4
0
bool parse_string(std::istream& input, String& value) {
    char ch = '\0', delimiter = '"';
    if (!match("\"", input))  {
        if (Parser == Strict) {
            return false;
        }
        delimiter = '\'';
        if (input.peek() != delimiter) {
            return false;
        }
        input.get(ch);
    }
    while(!input.eof() && input.good()) {
        input.get(ch);
        if (ch == delimiter) {
            break;
        }
        if (ch == '\\') {
            input.get(ch);
            switch(ch) {
                case '\\':
                case '/':
                    value.push_back(ch);
                    break;
                case 'b':
                    value.push_back('\b');
                    break;
                case 'f':
                    value.push_back('\f');
                    break;
                case 'n':
                    value.push_back('\n');
                    break;
                case 'r':
                    value.push_back('\r');
                    break;
                case 't':
                    value.push_back('\t');
                    break;
                case 'u': {
                        int i;
                        std::stringstream ss;
                        for( i = 0; (!input.eof() && input.good()) && i < 4; ++i ) {
                            input.get(ch);
                            ss << ch;
                        }
                        if( input.good() && (ss >> i) )
                            value.push_back(i);
                    }
                    break;
                default:
                    if (ch != delimiter) {
                        value.push_back('\\');
                        value.push_back(ch);
                    } else value.push_back(ch);
                    break;
            }
        } else {
Пример #5
0
String auxiliary::findPath(const Sidemarks& From, const Sidemarks& To, const bool& AllowMiddle)
{
  if(From==To  || From.type()!= To.type() || From.getEigenvalue()!=To.getEigenvalue())
  {
    return "";
  }
  typedef std::pair<Sidemarks,String>  state;
  std::list<state> Trace;
  Trace.push_back(state(From,"E")); // E means: Empty. It will be deleted before return
  while(true)
  {
    Sidemarks next_pos=Trace.front().first;
    String path=Trace.front().second;
    const char last_sign=path.back();
    const char last_move= is_letter(last_sign) ? last_sign : path[path.length()-2];
    const String sides(AllowMiddle ? "FRUBLD" : next_pos);
    C_FOR_STR(sides,s)
    {
      if(*s==last_move)
      {
	continue;
      }
      for(int mode=0;mode<3+(2*AllowMiddle);++mode)
      {
	String op;
	op.push_back(*s);
	switch(mode)
	{
	  case 1:  // inverse
	    op.push_back('\'');
	    break;
	  case 2:  // double
	    op.push_back('2');
	    break;
	  case 3:
	    op.push_back('|'); // middle side 
	    break;
	  case 4:
	    op.append("||");
	    break;
	  default:
	    ; // SKIP
	}
	Sidemarks next=next_pos+op;
	if(next==To)
	{
	  path.erase(path.begin());
	  return path+op;
	}
	Trace.push_back(state(next,path+op));
      }
    }
    Trace.pop_front();
  }
}
Пример #6
0
String processEscapes(const String& str)
{
  // Process all escaped characters
  String ret;
  for (unsigned i = 0; i < str.length(); i++) {
    if (str[i] == '\\' && i < str.length() - 1)
      ret.push_back(getUnescapedChar(str[++i]));
    else
      ret.push_back(str[i]);
  }

  return ret;
}
Пример #7
0
String utils::tab(int times) {
        String result = "";
        for (int i = 0; i < times; ++i) {
                result.push_back('\t');
        }
        return result;
}
Пример #8
0
String RandomUtils::randString(int length)
{
    String ret;
    for(auto i = 0; i < length; ++i)
        ret.push_back(randChar());
    return ret;
}
Пример #9
0
void base64LE_append(String &s, Int x, char const* base64code = base64url) {
  assert(good_base64_code(base64code));
  while(x) {
    s.push_back(base64code[x & 63]);
    x >>= 6;
  }
}
Пример #10
0
synfig::String
Action::Base::get_layer_descriptions(const std::list<std::pair<synfig::Layer::Handle,int> > layers, synfig::String singular_prefix, synfig::String plural_prefix)
{
	String ret;
	bool first = true;

	if (plural_prefix.empty())
		plural_prefix = singular_prefix;

	if (layers.empty())
		return plural_prefix;

	if (layers.size() == 1)
		ret = singular_prefix;
	else
		ret = plural_prefix;

	if (!ret.empty())
		ret.push_back(' ');

	for(std::list<std::pair<synfig::Layer::Handle,int> >::const_iterator iter=layers.begin(); iter!=layers.end(); ++iter)
	{
		if (first)
			first = false;
		else
			ret += ", ";

		ret += strprintf("'%s'", iter->first->get_non_empty_description().c_str());
	}

	return ret;
}
Пример #11
0
template<typename String, typename Iter> inline bool _parse_codepoint(String& out, input<Iter>& in) {
  int uni_ch;
  if ((uni_ch = _parse_quadhex(in)) == -1) {
    return false;
  }
  if (0xd800 <= uni_ch && uni_ch <= 0xdfff) {
    if (0xdc00 <= uni_ch) {
  // a second 16-bit of a surrogate pair appeared
  return false;
    }
    // first 16-bit of surrogate pair, get the next one
    if (in.getc() != '\\' || in.getc() != 'u') {
  in.ungetc();
  return false;
    }
    int second = _parse_quadhex(in);
    if (! (0xdc00 <= second && second <= 0xdfff)) {
  return false;
    }
    uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff);
    uni_ch += 0x10000;
  }
  if (uni_ch < 0x80) {
    out.push_back(uni_ch);
  } else {
    if (uni_ch < 0x800) {
  out.push_back(0xc0 | (uni_ch >> 6));
    } else {
  if (uni_ch < 0x10000) {
Пример #12
0
String RegExp::format(const char* str, const char* fmt, uint start)
{
	if (_peer == NULL) return fmt;

	String ret;

	SQRex* rex = (SQRex*)_peer;
	const char *begin, *end;
	bool found = sqstd_rex_search(rex, str+start, &begin, &end);
	if (!found) return ret;

	uint n = sqstd_rex_getsubexpcount(rex);

	for (const char* f = fmt; *f; ++f)
	{
		int ch = *f;
		if (ch != '%')
		{
			ret.push_back(ch);
			continue;
		}

		ch = *++f;

		if (ch == '*')
			ret.append(str);
		else if (ch == '<')
			ret.append(str, begin);
		else if (ch == '>')
			ret.append(end);
		else if ('0' <= ch && ch <= '9')
		{
			uint subIdx = ch - '0';
			if (subIdx < n)
			{
				SQRexMatch match;
				sqstd_rex_getsubexp(rex, subIdx, &match);
				ret.append(match.begin, match.len);
			}
			else
				NIT_THROW_FMT(EX_INVALID_PARAMS, "no subexp: %d", subIdx);
		}
		else ret.push_back(ch);
	}

	return ret;
}
Пример #13
0
String Map::GetMapDataAsText() {

	String mapDataAsText = "";
	mapDataAsText.push_back('\n');

	for (int y = m_size.y - 1; y >= 0; y--) {
		for (int x = 0; x < m_size.x; x++) {
			Tile* tile = GetTileAtLocation(IntVector2(x, y));

			switch (tile->GetCurrentTileType()) {
			case TILE_AIR:
				mapDataAsText.push_back('0');
				break;
			case TILE_STONE:
				mapDataAsText.push_back('#');
				break;
			case TILE_GRASS:
				mapDataAsText.push_back('.');
				break;
			case TILE_WATER:
				mapDataAsText.push_back('$');
				break;
			case TILE_LAVA:
				mapDataAsText.push_back('x');
				break;
			}
		}

		mapDataAsText.push_back('\n');
	}

	//String mapData = StringUtils::ReverseString(mapDataAsText);

	return mapDataAsText;
}
Пример #14
0
void CHttpServer::register_uri(String const &uri, CHttpServer::callback_t const &callback)
{
    if (uri.empty())
        return;
    String ruri = uri;
    if (ruri[ruri.size() - 1] != '/')
        ruri.push_back('/');
    m_registered[ruri] = callback;
}
Пример #15
0
void unescape3(ByteIt i, ByteIt e, String& s) {
  for (; i != e; ++i) {
    char c = *i;
    if (c != '\\')
      s.push_back(c);
    else {
      if (++i == e) throw Escape3Exception();
      c = *i;
      if (c == '\\')
        s.push_back(c);
      else {
        unsigned char high = hexdigit(c);
        if (++i == e) throw Escape3Exception();
        unsigned char low = hexdigit(*i);
        s.push_back(high * 16 + low);
      }
    }
  }
}
Пример #16
0
		static void OutputDebug(const LogDescription desc, const String& str)
		{
			String output;
			output.reserve(logLevelStr[static_cast<size_t>(desc)].length() + str.length() + 1);
			output.append(logLevelStr[static_cast<size_t>(desc)]);
			output.append(str);
			output.push_back(L'\n');

			::OutputDebugStringW(output.c_str());
		}
static String cleanPath(const String &s)
{
    String buf;
    for (unsigned int i=0 ; i<s.size() ; i++)
        {
        char ch = s[i];
        if (ch != '"')
            buf.push_back(ch);
		}
	return buf;
}
Пример #18
0
CHttpServer::callback_t CHttpServer::registered(String const &uri)
{
    if (uri.empty())
        return (callback_t)0;
    String ruri = uri;
    if (ruri[ruri.size() - 1] != '/')
        ruri.push_back('/');
    std::map<String, callback_t>::const_iterator it = m_registered.find(ruri);
    if (it == m_registered.end())
        return (callback_t)0;
    return it->second;
}
Пример #19
0
Token
Lexer::on_string()
{
  String str = build_.take();

  // Translate the spelling of the lexeme ion the basic
  // character set into the execution character set.
  String rep;
  rep.reserve(str.size());
  char const* p = str.c_str() + 1;
  while (*p != '\"') {
    if (*p != '\\')
      rep.push_back(*p);
    else
      rep.push_back(translate_escape(*++p));
    ++p;
  }
  Symbol* sym = syms_.put<String_sym>(str, string_tok, rep);

  return Token(loc_, string_tok, sym);
}
Пример #20
0
String reconstructPath(const String & path) {
	String ret; ret.reserve(path.size());
	bool start = (path.front() == '/');
	bool end = (path.back() == '/');

	Vector<CharReaderBase> retVec;
	CharReaderBase r(path);
	while (!r.empty()) {
		auto str = r.readUntil<CharReaderBase::Chars<'/'>>();
		if (str == ".." && str.size() == 2) {
			if (!retVec.empty()) {
				retVec.pop_back();
			}
		} else if ((str == "." && str.size() == 1) || str.size() == 0) {
		} else if (!str.empty()) {
			retVec.emplace_back(str);
		}
		if (r.is('/')) {
			++ r;
		}
	}

	if (start) {
		ret.push_back('/');
	}

	bool f = false;
	for (auto &it : retVec) {
		if (f) {
			ret.push_back('/');
		} else {
			f = true;
		}
		ret.append(it.data(), it.size());
	}
	if (end) {
		ret.push_back('/');
	}
	return ret;
}
Пример #21
0
void Map::RenderGlyphAtLocation(char glyph, const IntVector2& loc, const RGBA& col) {

	IntVector2 numTilesOnScreen = GetSize();
	Vector2 cellSize = Vector2(SCREEN_SIZE.x / (float)numTilesOnScreen.x, SCREEN_SIZE.y / (float)numTilesOnScreen.y);

	Vector2 positionToDrawFrom = loc.ToVector2() * cellSize;
	Vector2 positionToDrawTo = positionToDrawFrom + cellSize;

	String glyphStr = "";
	glyphStr.push_back(glyph);
	float lineHeight = abs((positionToDrawFrom.y - positionToDrawTo.y) * 0.75f);

	g_theUI->m_squirrelFont->DrawText2D(positionToDrawFrom, glyphStr, lineHeight, col);
}
Пример #22
0
inline String dataToHexHelper(const unsigned char *p, const unsigned char *end)
{
    if (p == end)
        return String();

    String rc;
    rc.reserve(2 * (end - p));
    for ( ; p < end ; ++p) {
        const unsigned c = *p;
        rc.push_back(toHexDigit(c / 16));
        rc.push_back(toHexDigit(c &0xF));
    }
    return rc;
}
Пример #23
0
/* ========================================================================
PURPOSE :
*/
int splitFiles (const char *sourceFilePath, const char *destDir)
{
    stJAndSHeader *splitHdr = NULL;
    FILE *fileHdl = NULL;        
    char splitName[_MAX_DIR];
    short nErr = EZERO;

    sprintf ( splitName, "%s%s", sourceFilePath, ".CAT" );

    if ((nErr = file_uncompress( sourceFilePath, splitName)) != 0) // @1
    {
        String msg = String("Failed uncompress from ") + sourceFilePath + " to "+ splitName;
        throw std::exception ( msg.c_str() );
        return nErr;
    }
        
    // Clear any outstanding errors
    errno = EZERO;

    // Get memory for the split header structure
    if ((splitHdr = (stJAndSHeader*)malloc(sizeof(stJAndSHeader))) != NULL)
    {
        // Open the join file...
        if ((fileHdl = fopen (splitName, "rb")) != NULL)
        {
            // Populate the header from the join file
            if (readHeader (splitHdr, fileHdl) == 0)
            {
                String strDestDir ( destDir );
                if ( strDestDir.back() != '\\' && strDestDir.back() != '/' )
                    strDestDir.push_back ( '/' );
                // ... and split out all the files.
                extractFiles ( strDestDir.c_str(), splitHdr, fileHdl );
            }
			fclose(fileHdl);
        }
        free (splitHdr);
    }
    else
        throw std::exception ("Insufficient memory");
    
    _unlink (splitName);

    // For debugging only
    #ifdef DEBUG_MODE
    printHeader (stdout,splitHdr);
    #endif

    return errno;
}
Пример #24
0
void PalindromeFunction::calculateAndWriteToVector(
            String string, IntVector &stringFunction) {
    stringFunction.resize(string.size() * 2 + 1);
    String specialString;
    specialString.push_back(specialSymbol);
    for (int currentPosition = 0; currentPosition < (int)string.size();
                currentPosition++) {
        specialString.push_back(string[currentPosition]);
        specialString.push_back(specialSymbol);
    }
    int mostRightBound = -1, mostRightBoundBegin = -1;
    for (int currentPosition = 0; currentPosition < (int)specialString.size();
                currentPosition++) {
        if (currentPosition < mostRightBound) {
            stringFunction[currentPosition] =
                std::min(stringFunction[2 * mostRightBoundBegin
                - currentPosition], mostRightBound - currentPosition);
        } else {
            stringFunction[currentPosition] = 0;
        }
        while (currentPosition + stringFunction[currentPosition]
                < (int)specialString.size()
                && currentPosition - stringFunction[currentPosition] >= 0
                && specialString[currentPosition
                    + stringFunction[currentPosition]]
                == specialString[currentPosition
                    - stringFunction[currentPosition]]) {
            stringFunction[currentPosition]++;
        }
        if (currentPosition + stringFunction[currentPosition]
                > mostRightBound) {
            mostRightBound = currentPosition
                + stringFunction[currentPosition];
            mostRightBoundBegin = currentPosition;
        }
    }
}
Пример #25
0
String URLRequest::urlEncode(const char* c, int len, bool fieldMode)
{
	String escaped;
	int max = len == -1 ? strlen(c) : len;
	for(int i=0; i<max; i++)
	{
		if ( (48 <= c[i] && c[i] <= 57) ||//0-9
			(65 <= c[i] && c[i] <= 90) ||//ABC...XYZ
			(97 <= c[i] && c[i] <= 122) || //abc...xyz
			(c[i]=='~' || c[i]=='-' || c[i]=='_' || c[i]=='.')
			)
		{
			escaped.push_back(c[i]);
		}
		else
		{
			if (fieldMode && (c[i] == '=' || c[i] == '&'))
				escaped.push_back(c[i]);
			else
			{
				escaped.push_back('%');

				char dec = c[i];
				char dig1 = (dec&0xF0)>>4;
				char dig2 = (dec&0x0F);
				if ( 0<= dig1 && dig1<= 9) dig1+=48;    //0,48 in ascii
				if (10<= dig1 && dig1<=15) dig1+=65-10; //A,65 in ascii
				if ( 0<= dig2 && dig2<= 9) dig2+=48;
				if (10<= dig2 && dig2<=15) dig2+=65-10;
				
				escaped.push_back(dig1);
				escaped.push_back(dig2);
			}
		}
	}
	return escaped;
}
Пример #26
0
String auxiliary::putInString(const std::string& arg, const char& sig, const String& text)
{
  String Result;
  C_FOR_STR(text,t)
  {
    if(*t!=sig)
    {
      Result.push_back(*t);
    }
    else
    {
      Result.append(arg);
    }
  }
  return Result;
}
 /// Append a second path to this one.
 /// @pre o's separator is the same as this one's, or o has no separators
 string_path& operator /=(const string_path &o) {
     // If it's single, there's no separator. This allows to do
     // p /= "piece";
     // even for non-default separators.
     assert((m_separator == o.m_separator || o.empty() || o.single())
            && "Incompatible paths.");
     if(!o.empty()) {
         String sub;
         if(!this->empty()) {
             sub.push_back(m_separator);
         }
         sub.insert(sub.end(), o.cstart(), o.m_value.end());
         detail::append_and_preserve_iter(m_value, sub, m_start,
             typename std::iterator_traits<s_iter>::iterator_category());
     }
     return *this;
 }
Пример #28
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;
}
Пример #29
0
String auxiliary::putInString(const String& arg1, const char& sig1, const String& arg2, const char& sig2, const String& text)
{
  String Result;
  C_FOR_STR(text,t)
  {
    if(*t==sig1)
    {
      Result.append(arg1);
    }
    else if(*t==sig2)
    {
      Result.append(arg2);
    }
    else
    {
      Result.push_back(*t);
    }
  }
  return Result;
}
Пример #30
0
AudioCodec::AudioCodec(String ext)
{
	if (lockCodecs()) return;
	Codecs &codecs = codecRegistry();

	Uint32 i = 0; String tmp; Char c;
	const Char *arr = ext.c_str();
	while (true)
	{
		c = arr[i]; ++i;
		if (!c || c == ',')
		{
			codecs.insert(Codec(tmp, this));
			tmp = L"";
			if (!c) break;
			continue;
		}
		if (c >= 'A' && c <= 'Z') c += ('a'-'A');
		tmp.push_back(c);
	}
}