Example #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;
}
Example #2
0
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;
}
Example #3
0
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;
}
Example #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();
}