Example #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;
}
Example #2
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 << std::hex << 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 {
Example #3
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;
}
Example #4
0
String RandomUtils::randString(int length)
{
    String ret;
    for(auto i = 0; i < length; ++i)
        ret.push_back(randChar());
    return ret;
}
Example #5
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;
}
Example #6
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;
}
Example #7
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);
      }
    }
  }
}
Example #8
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;
}
Example #9
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;
}
Example #10
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);
}
Example #11
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 #12
0
File: main.cpp Project: ECer23/stl
int main() {
  /*** check 1 ***/
  String a;
  String b("haha");

  cout << "a.size(): " << a.size() << endl;
  cout << "a.capacity(): " << a.capacity() << endl;
  cout << "b.size(): " << b.size() << endl;
  cout << "b.capacity(): " << b.capacity() << endl;

  a.push_back('a');
  a.push_back('b');
  a.reserve(8);

  cout << "a.size(): " << a.size() << endl;
  cout << "a.capacity(): " << a.capacity() << endl;

  b.pop_back();
  cout << "b.size(): " << b.size() << endl;
  cout << "b.capacity(): " << b.capacity() << endl;

  b.resize(8);
  cout << "b.size(): " << b.size() << endl;
  cout << "b.capacity(): " << b.capacity() << endl;

  /*** check 2 ***/
  String c("My name ");
  String d("is ");
  d += "Apple";
  String e = c + d;

  cout << c << endl;
  cout << d << endl;
  cout << e << endl;

  return 0;
}
Example #13
0
	proxy & operator =(char_type ch)
	{
		str->push_back(ch);
		return *this;
	}
Example #14
0
bool InputFunctor::operator ()(VariableReferencesList references, Kumir::String * error)
{
    // Clear state
    finishedFlag_ = false;
    inputValues_.clear();

    // Prepare input format for GUI
    String format;
    for (int i=0; i<(int)references.size(); i++) {
        if (references[i].baseType()==VT_int) {
            format.push_back('i');
        }
        else if (references[i].baseType()==VT_real) {
            format.push_back('r');
        }
        else if (references[i].baseType()==VT_bool) {
            format.push_back('b');
        }
        else if (references[i].baseType()==VT_char &&
                 references[i].isConstant() &&
                 references[i].value().toChar() == Char('\n'))
        {
            format.push_back('n');
        }
        else if (references[i].baseType()==VT_char) {
            format.push_back('c');
        }
        else if (references[i].baseType()==VT_string) {
            format.push_back('s');
        }
        else if (references[i].baseType()==VT_record) {
            const Variable & variable = references[i];
            const String typeFullName =
                    Kumir::Core::fromAscii(variable.recordModuleAsciiName())+
                    Kumir::Core::fromAscii("::")+
                    Kumir::Core::fromAscii(variable.recordClassAsciiName())+
                    Kumir::Core::fromAscii("::")+
                    variable.recordClassLocalizedName();
            format.append(typeFullName);
        }
        if (i<(int)references.size()-1) format.push_back(';');
    }

    const QString qFormat = QString::fromStdWString(format);

    // Request input action and wait for response
    emit requestInput(qFormat);
    forever {
        bool done = false;
        finishedMutex_->lock();
        done = finishedFlag_;
        finishedMutex_->unlock();
        if (runner_->mustStop()) {
            break;
        }
        else if (!done) {
            Util::SleepFunctions::msleep(1);
        }
        else {
            break;
        }
    }

    if (runner_->mustStop())
        return false; // Do nothing on exit

    // Store input values
    Q_ASSERT(inputValues_.size()==references.size());
    for (int i=0; i<inputValues_.size(); i++) {
        const AnyValue val = Util::QVariantToValue(inputValues_.at(i), 0);
        references[i].setValue(val);
    }
    return true;
}