Example #1
0
void KeyCursor::open(const Trie &trie,
                     const String &min_str,
                     const String &max_str,
                     UInt32 offset,
                     UInt32 limit,
                     UInt32 flags) {
  GRN_DAT_THROW_IF(PARAM_ERROR,
                   (min_str.ptr() == NULL) && (min_str.length() != 0));
  GRN_DAT_THROW_IF(PARAM_ERROR,
                   (max_str.ptr() == NULL) && (max_str.length() != 0));

  flags = fix_flags(flags);
  KeyCursor new_cursor(trie, offset, limit, flags);
  new_cursor.init(min_str, max_str);
  new_cursor.swap(this);
}
Example #2
0
Error VariantConstruct::parse(const String& p_string,Variant& r_ret,String &r_err_str,int &r_err_line,Variant::ObjectConstruct* p_construct,void* p_ud) {


	const CharType *str = p_string.ptr();
	int idx = 0;
	int len = p_string.length();
	Token token;
	r_err_line=0;
	String aux_key;

	Error err = _get_token(str,idx,len,token,r_err_line,r_err_str);
	if (err)
		return err;

	return _parse_value(r_ret,token,str,idx,len,r_err_line,r_err_str,p_construct,p_ud);
}
Example #3
0
File: json.cpp Project: 93i/godot
Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {

	const CharType *str = p_json.ptr();
	int idx = 0;
	int len = p_json.length();
	Token token;
	r_err_line = 0;
	String aux_key;

	Error err = _get_token(str, idx, len, token, r_err_line, r_err_str);
	if (err)
		return err;

	err = _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str);

	return err;
}
//-----------------------------------------------------------------------------
void Win32Context::setWindowTitle(const String& title)
{
    if (hwnd())
        SetWindowText(hwnd(), (wchar_t*)title.ptr());
}
Example #5
0
void KeyCursor::descending_init(const String &min_str, const String &max_str) {
  if (min_str.ptr() != NULL) {
    if (min_str.length() != 0) {
      end_buf_ = new UInt8[min_str.length()];
      std::memcpy(end_buf_, min_str.ptr(), min_str.length());
      end_str_.assign(end_buf_, min_str.length());
    }
  }

  if ((max_str.ptr() == NULL) || (max_str.length() == 0)) {
    buf_.push_back(ROOT_NODE_ID);
    return;
  }

  UInt32 node_id = ROOT_NODE_ID;
  for (UInt32 i = 0; i < max_str.length(); ++i) {
    const Base base = trie_->ith_node(node_id).base();
    if (base.is_linker()) {
      const Key &key = trie_->get_key(base.key_pos());
      const int result = key.str().compare(max_str, i);
      if ((result < 0) || ((result == 0) &&
          ((flags_ & EXCEPT_UPPER_BOUND) != EXCEPT_UPPER_BOUND))) {
        buf_.push_back(node_id | POST_ORDER_FLAG);
      }
      return;
    }

    UInt32 label = trie_->ith_node(node_id).child();
    if (label == TERMINAL_LABEL) {
      node_id = base.offset() ^ label;
      buf_.push_back(node_id | POST_ORDER_FLAG);
      label = trie_->ith_node(node_id).sibling();
    }
    while (label != INVALID_LABEL) {
      node_id = base.offset() ^ label;
      if (label < max_str[i]) {
        buf_.push_back(node_id);
      } else if (label > max_str[i]) {
        return;
      } else {
        break;
      }
      label = trie_->ith_node(node_id).sibling();
    }
    if (label == INVALID_LABEL) {
      return;
    }
  }

  const Base base = trie_->ith_node(node_id).base();
  if (base.is_linker()) {
    const Key &key = trie_->get_key(base.key_pos());
    if ((key.length() == max_str.length()) &&
        ((flags_ & EXCEPT_UPPER_BOUND) != EXCEPT_UPPER_BOUND)) {
      buf_.push_back(node_id | POST_ORDER_FLAG);
    }
    return;
  }

  UInt16 label = trie_->ith_node(node_id).child();
  if ((label == TERMINAL_LABEL) &&
      ((flags_ & EXCEPT_UPPER_BOUND) != EXCEPT_UPPER_BOUND)) {
    buf_.push_back((base.offset() ^ label) | POST_ORDER_FLAG);
  }
}
Example #6
0
void KeyCursor::ascending_init(const String &min_str, const String &max_str) {
  if (max_str.ptr() != NULL) {
    if (max_str.length() != 0) {
      end_buf_ = new UInt8[max_str.length()];
      std::memcpy(end_buf_, max_str.ptr(), max_str.length());
      end_str_.assign(end_buf_, max_str.length());
    }
  }

  if ((min_str.ptr() == NULL) || (min_str.length() == 0)) {
    buf_.push_back(ROOT_NODE_ID);
    return;
  }

  UInt32 node_id = ROOT_NODE_ID;
  Node node;
  for (UInt32 i = 0; i < min_str.length(); ++i) {
    node = trie_->ith_node(node_id);
    if (node.is_linker()) {
      const Key &key = trie_->get_key(node.key_pos());
      const int result = key.str().compare(min_str, i);
      if ((result > 0) || ((result == 0) &&
          ((flags_ & EXCEPT_LOWER_BOUND) != EXCEPT_LOWER_BOUND))) {
        buf_.push_back(node_id);
      } else if (node.sibling() != INVALID_LABEL) {
        buf_.push_back(node_id ^ node.label() ^ node.sibling());
      }
      return;
    } else if (node.sibling() != INVALID_LABEL) {
      buf_.push_back(node_id ^ node.label() ^ node.sibling());
    }

    node_id = node.offset() ^ min_str[i];
    if (trie_->ith_node(node_id).label() != min_str[i]) {
      UInt16 label = node.child();
      if (label == TERMINAL_LABEL) {
        label = trie_->ith_node(node.offset() ^ label).sibling();
      }
      while (label != INVALID_LABEL) {
        if (label > min_str[i]) {
          buf_.push_back(node.offset() ^ label);
          break;
        }
        label = trie_->ith_node(node.offset() ^ label).sibling();
      }
      return;
    }
  }

  node = trie_->ith_node(node_id);
  if (node.is_linker()) {
    const Key &key = trie_->get_key(node.key_pos());
    if ((key.length() != min_str.length()) ||
        ((flags_ & EXCEPT_LOWER_BOUND) != EXCEPT_LOWER_BOUND)) {
      buf_.push_back(node_id);
    } else if (node.sibling() != INVALID_LABEL) {
      buf_.push_back(node_id ^ node.label() ^ node.sibling());
    }
    return;
  } else if (node.sibling() != INVALID_LABEL) {
    buf_.push_back(node_id ^ node.label() ^ node.sibling());
  }

  UInt16 label = node.child();
  if ((label == TERMINAL_LABEL) &&
      ((flags_ & EXCEPT_LOWER_BOUND) == EXCEPT_LOWER_BOUND)) {
    label = trie_->ith_node(node.offset() ^ label).sibling();
  }
  if (label != INVALID_LABEL) {
    buf_.push_back(node.offset() ^ label);
  }
}