Пример #1
0
StaticString::StaticString(litstr s) : m_data(s) {
  String::operator=(&m_data);
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #2
0
void String::unserialize(std::istream &in,
                         char delimiter0 /* = '"' */,
                         char delimiter1 /* = '"' */) {
  int size;
  in >> size;
  if (size >= SERIALIZE_MAX_SIZE) {
    throw Exception("Size of serialized string (%d) exceeds max", size);
  }

  char ch;
  in >> ch;
  if (ch != ':') {
    throw Exception("Expected ':' but got '%c'", ch);
  }
  in >> ch;
  if (ch != delimiter0) {
    throw Exception("Expected '%c' but got '%c'", delimiter0, ch);
  }

  char *buf = (char*)malloc(size + 1);
  in.read(buf, size);
  buf[size] = '\0';
  SmartPtr<StringData>::operator=(NEW(StringData)(buf, size, AttachString));

  in >> ch;
  if (ch != delimiter1) {
    throw Exception("Expected '%c' but got '%c'", delimiter1, ch);
  }

  checkStatic();
}
Пример #3
0
StaticString::StaticString(const StaticString &str)
  : m_data(str.m_data.data(), str.m_data.size(), AttachLiteral) {
  String::operator=(&m_data);
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #4
0
StaticString::StaticString(std::string s)
  : m_data(s.c_str(), s.size(), CopyString) {
  String::operator=(&m_data);
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #5
0
StaticString::StaticString(litstr s, int length)
  : m_data(s, length, AttachLiteral) {
  String::operator=(&m_data);
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #6
0
void StaticString::init(litstr s, int length) {
  new(&m_data) StringData(s, length, AttachLiteral);
  ASSERT(!m_px);
  String::operator=(&m_data);
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #7
0
StaticString::StaticString(litstr s) : m_data(s) {
  m_px = &m_data;
  if (has_eval_support) {
    m_px = StringData::GetStaticString(m_px);
    return;
  }
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #8
0
StaticString::StaticString(const StaticString &str)
  : m_data(str.m_data.data(), str.m_data.size(), AttachLiteral) {
  String::operator=(&m_data);
  if (has_eval_support) {
    m_px = StringData::GetStaticString(m_px);
    return;
  }
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #9
0
StaticString::StaticString(std::string s)
  : m_data(s.c_str(), s.size(), CopyString) {
  String::operator=(&m_data);
  if (has_eval_support) {
    m_px = StringData::GetStaticString(m_px);
    return;
  }
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #10
0
StaticString::StaticString(litstr s, int length)
  : m_data(s, length, AttachLiteral) {
  m_px = &m_data;
  if (has_eval_support) {
    m_px = StringData::GetStaticString(m_px);
    return;
  }
  m_px->setStatic();
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #11
0
void StaticString::init(litstr s, int length) {
  new(&m_data) StringData(s, length, AttachLiteral);
  ASSERT(!m_px);
  String::operator=(&m_data);
  m_px->setStatic();
  if (has_eval_support) {
    m_px = StringData::GetStaticString(m_px);
    return;
  }
  if (!checkStatic()) {
    s_stringSet->insert(m_px);
  }
}
Пример #12
0
void String::unserialize(VariableUnserializer *uns,
                         char delimiter0 /* = '"' */,
                         char delimiter1 /* = '"' */) {
  int64 size = uns->readInt();
  if (size >= RuntimeOption::MaxSerializedStringSize) {
    throw Exception("Size of serialized string (%d) exceeds max", int(size));
  }
  if (size < 0) {
    throw Exception("Size of serialized string (%d) must not be negative",
                    int(size));
  }

  char ch = uns->readChar();
  if (ch != ':') {
    throw Exception("Expected ':' but got '%c'", ch);
  }
  ch = uns->readChar();
  if (ch != delimiter0) {
    throw Exception("Expected '%c' but got '%c'", delimiter0, ch);
  }
  StringData *px = NEW(StringData)(int(size));
  MutableSlice buf = px->mutableSlice();
  ASSERT(size <= buf.len);
  uns->read(buf.ptr, size);
  px->setSize(size);
  if (m_px && m_px->decRefCount() == 0) {
    m_px->release();
  }
  m_px = px;
  px->setRefCount(1);

  ch = uns->readChar();
  if (ch != delimiter1) {
    throw Exception("Expected '%c' but got '%c'", delimiter1, ch);
  }

  checkStatic();
}
Пример #13
0
void String::unserialize(VariableUnserializer *uns,
                         char delimiter0 /* = '"' */,
                         char delimiter1 /* = '"' */) {
  int64 size = uns->readInt();
  if (size >= RuntimeOption::MaxSerializedStringSize) {
    throw Exception("Size of serialized string (%d) exceeds max", int(size));
  }
  if (size < 0) {
    throw Exception("Size of serialized string (%d) must not be negative",
                    int(size));
  }

  char ch = uns->readChar();
  if (ch != ':') {
    throw Exception("Expected ':' but got '%c'", ch);
  }
  ch = uns->readChar();
  if (ch != delimiter0) {
    throw Exception("Expected '%c' but got '%c'", delimiter0, ch);
  }

  char *buf = (char*)malloc(size + 1);
  uns->read(buf, size);
  buf[size] = '\0';
  if (m_px && m_px->decRefCount() == 0) {
    m_px->release();
  }
  m_px = NEW(StringData)(buf, size, AttachString);
  m_px->setRefCount(1);

  ch = uns->readChar();
  if (ch != delimiter1) {
    throw Exception("Expected '%c' but got '%c'", delimiter1, ch);
  }

  checkStatic();
}