示例#1
0
void
URLSearchParams::ParseInput(const nsACString& aInput,
                            URLSearchParamsObserver* aObserver)
{
  // Remove all the existing data before parsing a new input.
  DeleteAll();

  nsACString::const_iterator start, end;
  aInput.BeginReading(start);
  aInput.EndReading(end);
  nsACString::const_iterator iter(start);

  while (start != end) {
    nsAutoCString string;

    if (FindCharInReadable('&', iter, end)) {
      string.Assign(Substring(start, iter));
      start = ++iter;
    } else {
      string.Assign(Substring(start, end));
      start = end;
    }

    if (string.IsEmpty()) {
      continue;
    }

    nsACString::const_iterator eqStart, eqEnd;
    string.BeginReading(eqStart);
    string.EndReading(eqEnd);
    nsACString::const_iterator eqIter(eqStart);

    nsAutoCString name;
    nsAutoCString value;

    if (FindCharInReadable('=', eqIter, eqEnd)) {
      name.Assign(Substring(eqStart, eqIter));

      ++eqIter;
      value.Assign(Substring(eqIter, eqEnd));
    } else {
      name.Assign(string);
    }

    nsAutoCString decodedName;
    DecodeString(name, decodedName);

    nsAutoCString decodedValue;
    DecodeString(value, decodedValue);

    AppendInternal(NS_ConvertUTF8toUTF16(decodedName),
                   NS_ConvertUTF8toUTF16(decodedValue));
  }

  NotifyObservers(aObserver);
}
示例#2
0
void
URLSearchParams::Append(const nsAString& aName, const nsAString& aValue)
{
  // Before setting any new value we have to be sure to have all the previous
  // values in place.
  Validate();

  AppendInternal(aName, aValue);
  NotifyObserver();
}
示例#3
0
void
URLSearchParams::Append(const nsAString& aName, const nsAString& aValue)
{
  AppendInternal(aName, aValue);
  NotifyObservers(nullptr);
}