예제 #1
0
static bool
ReadTextFile(const TCHAR *path, tstring &buffer)
{
  /* auto-detect the character encoding, to be able to parse XCSoar
     6.0 task files */
  FileLineReader reader(path, ConvertLineReader::AUTO);
  if (reader.error())
    return false;

  long size = reader.size();
  if (size > 65536)
    return false;
  else if (size < 0)
    size = 4096;

  buffer.reserve(size);

  const TCHAR *line;
  while ((line = reader.read()) != NULL) {
    if (buffer.length() > 65536)
      /* too long */
      return false;

    buffer.append(line);
    buffer.append(_T("\n"));
  }

  return true;
}
예제 #2
0
파일: Parser.cpp 프로젝트: Advi42/XCSoar
static bool
ReadTextFile(Path path, tstring &buffer)
try {
  /* auto-detect the character encoding, to be able to parse XCSoar
     6.0 task files */
  FileLineReader reader(path, Charset::AUTO);

  long size = reader.GetSize();
  if (size > 65536)
    return false;
  else if (size < 0)
    size = 4096;

  buffer.reserve(size);

  const TCHAR *line;
  while ((line = reader.ReadLine()) != nullptr) {
    if (buffer.length() > 65536)
      /* too long */
      return false;

    buffer.append(line);
    buffer.append(_T("\n"));
  }

  return true;
} catch (const std::runtime_error &) {
  return false;
}
예제 #3
0
파일: pnutils.cpp 프로젝트: ALPHAMARIOX/pn
void XMLSafeString(tstring& str)
{
	// make an attempt at reducing re-allocs...
	int len = str.size();
	TCHAR * buffer = new TCHAR[len+1];
	_tcscpy(buffer, str.c_str());
	str.reserve(len + 20);
	str = _T("");
	
	XMLSafeString(buffer, str);

	delete [] buffer;
}
예제 #4
0
void
NOAAFormatter::Format(const NOAAStore::Item &station, tstring &output)
{
  output.reserve(2048);

  if (!station.metar_available) {
    output += _("No METAR available!");
  } else {
    if (station.parsed_metar_available)
      FormatDecodedMETAR(station.metar, station.parsed_metar, output);
    else
      output += station.metar.decoded.c_str();

    output += _T("\n\n");
    output += station.metar.content.c_str();
  }

  output += _T("\n\n");

  if (!station.taf_available)
    output += _("No TAF available!");
  else
    output += station.taf.content.c_str();
}