示例#1
0
unsigned
TaskFileSeeYou::Count()
{
  // Reset internal task name memory
  namesuffixes.clear();

  // Open the CUP file
  FileLineReader reader(path, ConvertLineReader::AUTO);
  if (reader.error())
    return 0;

  unsigned count = 0;
  bool in_task_section = false;
  TCHAR *line;
  while ((line = reader.ReadLine()) != NULL) {
    if (in_task_section) {
      // If the line starts with a string or "nothing" followed
      // by a comma it is a new task definition line
      if (line[0] == _T('\"') || line[0] == _T(',')) {
        // If we still have space in the task name list
        if (count < namesuffixes.capacity()) {
          // If the task doesn't have a name inside the file
          if (line[0] == _T(','))
            namesuffixes.append(NULL);
          else {
            // Ignore starting quote (")
            line++;

            // Save pointer to first character
            TCHAR *name = line;
            // Skip characters until next quote (") or end of string
            while (line[0] != _T('\"') && line[0] != _T('\0'))
              line++;

            // Replace quote (") by end of string (null)
            line[0] = _T('\0');

            // Append task name to the list
            if (_tcslen(name) > 0)
              namesuffixes.append(_tcsdup(name));
            else
              namesuffixes.append(NULL);
          }
        }

        // Increase the task counter
        count++;
      }
    } else if (StringIsEqualIgnoreCase(line, _T("-----Related Tasks-----"))) {
      // Found the marker -> all following lines are task lines
      in_task_section = true;
    }
  }

  // Return number of tasks found in the CUP file
  return count;
}
示例#2
0
DataNode::List
DataNodeXML::ListChildrenNamed(const TCHAR *name) const
{
    List list;
    for (auto i = node.begin(), end = node.end(); i != end; ++i)
        if (StringIsEqualIgnoreCase(i->GetName(), name))
            list.push_back(new DataNodeXML(*i));
    return list;
}
示例#3
0
gcc_pure
static bool
CompareRegistryValue(const RegistryKey &registry,
                     const TCHAR *name, const TCHAR *value)
{
  TCHAR real_value[64];
  return registry.GetValue(name, real_value, 64) &&
    StringIsEqualIgnoreCase(value, real_value);
}
示例#4
0
bool
StringEndsWithIgnoreCase(const char *haystack, const char *needle)
{
  const size_t haystack_length = StringLength(haystack);
  const size_t needle_length = StringLength(needle);

  return haystack_length >= needle_length &&
    StringIsEqualIgnoreCase(haystack + haystack_length - needle_length,
                            needle);
}
示例#5
0
文件: Path.cpp 项目: Advi42/XCSoar
bool
Path::MatchesExtension(const_pointer extension) const
{
  size_t filename_length = StringLength(c_str());
  size_t extension_length = StringLength(extension);

  return filename_length > extension_length &&
    StringIsEqualIgnoreCase(c_str() + filename_length - extension_length,
                            extension);
}
示例#6
0
const TCHAR *
XMLNode::GetAttribute(const TCHAR *name) const
{
  if (!d)
    return nullptr;

  for (auto i = d->attributes.begin(), end = d->attributes.end();
       i != end; ++i)
    if (StringIsEqualIgnoreCase(i->name.c_str(), name))
      return i->value.c_str();

  return nullptr;
}
示例#7
0
const XMLNode *
XMLNode::GetChildNode(const TCHAR *name) const
{
  if (!d)
    return nullptr;

  for (auto i = d->begin(), end = d->end(); i != end; ++i) {
    const XMLNode &node = *i;
    if (StringIsEqualIgnoreCase(node.d->name.c_str(), name))
      return &node;
  }

  return nullptr;
}
示例#8
0
static bool
ParseDistance(const TCHAR *src, double &dest)
{
  // Parse string
  TCHAR *endptr;
  double value = _tcstod(src, &endptr);
  if (endptr == src)
    return false;

  dest = value;

  // Convert to system unit if necessary, assume m as default
  TCHAR* unit = endptr;
  if (StringIsEqualIgnoreCase(unit, _T("ml")))
    dest = Units::ToSysUnit(dest, Unit::STATUTE_MILES);
  else if (StringIsEqualIgnoreCase(unit, _T("nm")))
    dest = Units::ToSysUnit(dest, Unit::NAUTICAL_MILES);
  else if (StringIsEqualIgnoreCase(unit, _T("ft")))
    dest = Units::ToSysUnit(dest, Unit::FEET);

  // Save distance
  return true;
}
示例#9
0
static bool
ClearSuffix(TCHAR *p, const TCHAR *suffix)
{
  size_t length = _tcslen(p);
  size_t suffix_length = _tcslen(suffix);
  if (length <= suffix_length)
    return false;

  TCHAR *q = p + length - suffix_length;
  if (!StringIsEqualIgnoreCase(q, suffix))
    return false;

  *q = _T('\0');
  return true;
}
示例#10
0
static AirspaceClass
ParseTypeTNP(const TCHAR *buffer)
{
  // Handle e.g. "TYPE=CLASS C" properly
  const TCHAR *type = StringAfterPrefixCI(buffer, _T("CLASS "));
  if (type) {
    AirspaceClass _class = ParseClassTNP(type);
    if (_class != OTHER)
      return _class;
  } else {
    type = buffer;
  }

  for (unsigned i = 0; i < ARRAY_SIZE(airspace_tnp_type_strings); i++)
    if (StringIsEqualIgnoreCase(type, airspace_tnp_type_strings[i].string))
      return airspace_tnp_type_strings[i].type;

  return OTHER;
}
示例#11
0
ProfilePasswordResult
CheckProfilePassword(const ProfileMap &map)
{
  /* oh no, profile passwords are not truly secure! */

  StringBuffer<TCHAR, 80> profile_password;
  if (!map.Get(ProfileKeys::Password, profile_password))
      /* not password protected */
      return ProfilePasswordResult::UNPROTECTED;

  StringBuffer<TCHAR, 80> user_password;
  user_password.clear();
  if (!TextEntryDialog(user_password, _("Enter your password")))
    return ProfilePasswordResult::CANCEL;

  return StringIsEqualIgnoreCase(profile_password, user_password)
    ? ProfilePasswordResult::MATCH
    : ProfilePasswordResult::MISMATCH;
}
示例#12
0
static TCHAR *
AdvanceReaderToTask(FileLineReader &reader, const unsigned index)
{
  // Skip lines until n-th task
  unsigned count = 0;
  bool in_task_section = false;
  TCHAR *line;
  for (unsigned i = 0; (line = reader.ReadLine()) != NULL; i++) {
    if (in_task_section) {
      if (line[0] == _T('\"') || line[0] == _T(',')) {
        if (count == index)
          break;

        count++;
      }
    } else if (StringIsEqualIgnoreCase(line, _T("-----Related Tasks-----"))) {
      in_task_section = true;
    }
  }
  return line;
}
示例#13
0
文件: Parser.cpp 项目: Advi42/XCSoar
gcc_pure
static bool
CompareTagName(const TCHAR *cclose, const TCHAR *copen)
{
  assert(cclose != nullptr);
  assert(copen != nullptr);

  size_t l = _tcslen(cclose);
  if (!StringIsEqualIgnoreCase(cclose, copen, l))
    return false;

  const TCHAR c = copen[l];
  if (IsWhitespaceOrNull(c) ||
      (c == _T('/')) ||
      (c == _T('<')) ||
      (c == _T('>')) ||
      (c == _T('=')))
    return true;

  return false;
}
示例#14
0
static bool
CompareTagName(const TCHAR *cclose, const TCHAR *copen)
{
  if (!cclose)
    return false;
  size_t l = _tcslen(cclose);
  if (!StringIsEqualIgnoreCase(cclose, copen, l))
    return false;

  const TCHAR c = copen[l];
  if ((c == _T('\n')) ||
      (c == _T(' ')) ||
      (c == _T('\t')) ||
      (c == _T('\r')) ||
      (c == _T('/')) ||
      (c == _T('<')) ||
      (c == _T('>')) ||
      (c == _T('=')))
    return true;

  return false;
}
示例#15
0
static void
ReadAltitude(const TCHAR *buffer, AirspaceAltitude &altitude)
{
  Unit unit = Unit::FEET;
  enum { MSL, AGL, SFC, FL, STD, UNLIMITED } type = MSL;
  fixed value = fixed(0);

  const TCHAR *p = buffer;
  while (true) {
    while (*p == _T(' '))
      ++p;

    if (IsDigitASCII(*p)) {
      TCHAR *endptr;
      value = fixed(ParseDouble(p, &endptr));
      p = endptr;
    } else if (StringIsEqualIgnoreCase(p, _T("GND"), 3) ||
               StringIsEqualIgnoreCase(p, _T("AGL"), 3)) {
      type = AGL;
      p += 3;
    } else if (StringIsEqualIgnoreCase(p, _T("SFC"), 3)) {
      type = SFC;
      p += 3;
    } else if (StringIsEqualIgnoreCase(p, _T("FL"), 2)) {
      type = FL;
      p += 2;
    } else if (*p == _T('F') || *p == _T('f')) {
      unit = Unit::FEET;
      ++p;

      if (*p == _T('T') || *p == _T('t'))
        ++p;
    } else if (StringIsEqualIgnoreCase(p, _T("MSL"), 3)) {
      type = MSL;
      p += 3;
    } else if (*p == _T('M') || *p == _T('m')) {
      unit = Unit::METER;
      ++p;
    } else if (StringIsEqualIgnoreCase(p, _T("STD"), 3)) {
      type = STD;
      p += 3;
    } else if (StringIsEqualIgnoreCase(p, _T("UNL"), 3)) {
      type = UNLIMITED;
      p += 3;
    } else if (*p == _T('\0'))
      break;
    else
      ++p;
  }

  switch (type) {
  case FL:
    altitude.reference = AltitudeReference::STD;
    altitude.flight_level = value;
    return;

  case UNLIMITED:
    altitude.reference = AltitudeReference::MSL;
    altitude.altitude = fixed(50000);
    return;

  case SFC:
    altitude.reference = AltitudeReference::AGL;
    altitude.altitude_above_terrain = fixed(-1);
    return;

  default:
    break;
  }

  // For MSL, AGL and STD we convert the altitude to meters
  value = Units::ToSysUnit(value, unit);
  switch (type) {
  case MSL:
    altitude.reference = AltitudeReference::MSL;
    altitude.altitude = value;
    return;

  case AGL:
    altitude.reference = AltitudeReference::AGL;
    altitude.altitude_above_terrain = value;
    return;

  case STD:
    altitude.reference = AltitudeReference::STD;
    altitude.flight_level = Units::ToUserUnit(value, Unit::FLIGHT_LEVEL);
    return;

  default:
    break;
  }
}
示例#16
0
文件: Parser.cpp 项目: Advi42/XCSoar
/**
 * This function is the opposite of the function "toXMLString". It
 * decodes the escape sequences &amp;, &quot;, &apos;, &lt;, &gt; and
 * replace them by the characters &,",',<,>. This function is used
 * internally by the XML Parser. All the calls to the XML library will
 * always gives you back "decoded" strings.
 *
 * @param ss string
 * @param lo length of string
 * @return new allocated string converted from xml
 */
static TCHAR *
FromXMLString(const TCHAR *ss, size_t lo)
{
  assert(ss != nullptr);

  const TCHAR *end = ss + lo;

  /* allocate a buffer with the size of the input string; we know for
     sure that this is enough, because resolving entities can only
     shrink the string, but never grows */
  TCHAR *d = (TCHAR *)malloc((lo + 1) * sizeof(*d));
  assert(d);
  TCHAR *result = d;
  while (ss < end && *ss) {
    if (*ss == _T('&')) {
      ss++;
      if (StringIsEqualIgnoreCase(ss, _T("lt;" ), 3)) {
        *(d++) = _T('<' );
        ss += 3;
      } else if (StringIsEqualIgnoreCase(ss, _T("gt;" ), 3)) {
        *(d++) = _T('>' );
        ss += 3;
      } else if (StringIsEqualIgnoreCase(ss, _T("amp;" ), 4)) {
        *(d++) = _T('&' );
        ss += 4;
      } else if (StringIsEqualIgnoreCase(ss, _T("apos;"), 5)) {
        *(d++) = _T('\'');
        ss += 5;
      } else if (StringIsEqualIgnoreCase(ss, _T("quot;"), 5)) {
        *(d++) = _T('"' );
        ss += 5;
      } else if (*ss == '#') {
        /* number entity */

        ++ss;

        TCHAR *endptr;
        unsigned i = ParseUnsigned(ss, &endptr, 10);
        if (endptr == ss || endptr >= end || *endptr != ';') {
          free(result);
          return nullptr;
        }

        // XXX convert to UTF-8 if !_UNICODE
        TCHAR ch = (TCHAR)i;
        if (ch == 0)
          ch = ' ';

        *d++ = ch;
        ss = endptr + 1;
      } else {
        free(result);
        return nullptr;
      }
    } else {
      *(d++) = *ss;
      ss++;
    }
  }
  *d = 0;

  /* shrink the memory allocation just in case we allocated too
     much */
  d = (TCHAR *)realloc(result, (d + 1 - result) * sizeof(*d));
  if (d != nullptr)
    result = d;

  return result;
}
示例#17
0
bool
AbstractAirspace::MatchNamePrefix(const TCHAR *prefix) const
{
  size_t prefix_length = _tcslen(prefix);
  return StringIsEqualIgnoreCase(name.c_str(), prefix, prefix_length);
}
示例#18
0
static bool
ParseLineTNP(Airspaces &airspace_database, TCHAR *line,
             TempAirspaceType &temp_area, bool &ignore)
{
  // Strip comments
  TCHAR *comment = _tcschr(line, _T('*'));
  if (comment != nullptr)
    *comment = _T('\0');

  const TCHAR* parameter;
  if ((parameter = StringAfterPrefixCI(line, _T("INCLUDE="))) != nullptr) {
    if (StringStartsWithIgnoreCase(parameter, _T("YES")))
      ignore = false;
    else if (StringStartsWithIgnoreCase(parameter, _T("NO")))
      ignore = true;

    return true;
  }

  if (ignore)
    return true;

  if ((parameter = StringAfterPrefixCI(line, _T("POINT="))) != nullptr) {
    GeoPoint temp_point;
    if (!ParseCoordsTNP(parameter, temp_point))
      return false;

    temp_area.points.push_back(temp_point);
  } else if ((parameter =
      StringAfterPrefixCI(line, _T("CIRCLE "))) != nullptr) {
    if (!ParseCircleTNP(parameter, temp_area))
      return false;

    temp_area.AddCircle(airspace_database);
    temp_area.ResetTNP();
  } else if ((parameter =
      StringAfterPrefixCI(line, _T("CLOCKWISE "))) != nullptr) {
    temp_area.rotation = 1;
    if (!ParseArcTNP(parameter, temp_area))
      return false;
  } else if ((parameter =
      StringAfterPrefixCI(line, _T("ANTI-CLOCKWISE "))) != nullptr) {
    temp_area.rotation = -1;
    if (!ParseArcTNP(parameter, temp_area))
      return false;
  } else if ((parameter = StringAfterPrefixCI(line, _T("TITLE="))) != nullptr) {
    temp_area.AddPolygon(airspace_database);
    temp_area.ResetTNP();

    temp_area.name = parameter;
  } else if ((parameter = StringAfterPrefixCI(line, _T("TYPE="))) != nullptr) {
    temp_area.AddPolygon(airspace_database);
    temp_area.ResetTNP();

    temp_area.type = ParseTypeTNP(parameter);
  } else if ((parameter = StringAfterPrefixCI(line, _T("CLASS="))) != nullptr) {
    temp_area.type = ParseClassTNP(parameter);
  } else if ((parameter = StringAfterPrefixCI(line, _T("TOPS="))) != nullptr) {
    ReadAltitude(parameter, temp_area.top);
  } else if ((parameter = StringAfterPrefixCI(line, _T("BASE="))) != nullptr) {
    ReadAltitude(parameter, temp_area.base);
  } else if ((parameter = StringAfterPrefixCI(line, _T("RADIO="))) != nullptr) {
    temp_area.radio = parameter;
  } else if ((parameter = StringAfterPrefixCI(line, _T("ACTIVE="))) != nullptr) {
    if (StringIsEqualIgnoreCase(parameter, _T("WEEKEND")))
      temp_area.days_of_operation.SetWeekend();
    else if (StringIsEqualIgnoreCase(parameter, _T("WEEKDAY")))
      temp_area.days_of_operation.SetWeekdays();
    else if (StringIsEqualIgnoreCase(parameter, _T("EVERYDAY")))
      temp_area.days_of_operation.SetAll();
  }

  return true;
}