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

  flags = fix_flags(flags);
  PredictiveCursor new_cursor(trie, offset, limit, flags);
  new_cursor.init(str);
  new_cursor.swap(this);
}
Example #2
0
void IdCursor::open(const Trie &trie,
                    const String &min_str,
                    const String &max_str,
                    UInt32 offset,
                    UInt32 limit,
                    UInt32 flags) {
  UInt32 min_id = INVALID_KEY_ID;
  if (min_str.ptr() != NULL) {
    UInt32 key_pos;
    GRN_DAT_THROW_IF(PARAM_ERROR,
                     !trie.search(min_str.ptr(), min_str.length(), &key_pos));
    min_id = trie.get_key(key_pos).id();
  }

  UInt32 max_id = INVALID_KEY_ID;
  if (max_str.ptr() != NULL) {
    UInt32 key_pos;
    GRN_DAT_THROW_IF(PARAM_ERROR,
                     !trie.search(max_str.ptr(), max_str.length(), &key_pos));
    max_id = trie.get_key(key_pos).id();
  }

  open(trie, min_id, max_id, offset, limit, flags);
}
Example #3
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 #4
0
bool ShaderMaterial::_set(const StringName& p_name, const Variant& p_value) {

	if (p_name==SceneStringNames::get_singleton()->shader_shader) {
		set_shader(p_value);
		return true;
	} else {

		String n = p_name;
		if (n.begins_with("param/")) {
			VisualServer::get_singleton()->material_set_param(material,String(n.ptr()+6),p_value);
			return true;
		}
	}

	return false;
}
Example #5
0
String FormatValue(__int64 Value)
{
  int pw = 0;
  __int64 div = 1;
  while (Value >= 100000) { div *= 1024; Value /= 1024; pw++; }
  String UnitStr;
  switch (pw) 
  {
    case 0: UnitStr = LOC("Engine.Bytes"); break;
    case 1: UnitStr = LOC("Engine.Kb"); break;
    case 2: UnitStr = LOC("Engine.Mb"); break;
    case 3: UnitStr = LOC("Engine.Gb"); break;
    case 4: UnitStr = LOC("Engine.Tb"); break;
    case 5: UnitStr = LOC("Engine.Pb"); break;
  }
  return Format(L"%s %s", FormatNum(Value).ptr(), UnitStr.ptr());
}
  void ConditionConverter::append_const_item(const Item_field *field_item,
                                             Item *const_item,
                                             grn_obj *expression) {
    MRN_DBUG_ENTER_METHOD();

    enum_field_types field_type = field_item->field_type();
    NormalizedType normalized_type = normalize_field_type(field_type);

    switch (normalized_type) {
    case STRING_TYPE:
      grn_obj_reinit(ctx_, &value_, GRN_DB_TEXT, 0);
      {
        String *string;
        string = const_item->val_str(NULL);
        GRN_TEXT_SET(ctx_, &value_, string->ptr(), string->length());
      }
      break;
    case INT_TYPE:
      grn_obj_reinit(ctx_, &value_, GRN_DB_INT64, 0);
      GRN_INT64_SET(ctx_, &value_, const_item->val_int());
      break;
    case TIME_TYPE:
      grn_obj_reinit(ctx_, &value_, GRN_DB_TIME, 0);
      {
        MYSQL_TIME mysql_time;
        get_time_value(field_item, const_item, &mysql_time);
        bool truncated = false;
        TimeConverter time_converter;
        long long int time =
          time_converter.mysql_time_to_grn_time(&mysql_time, &truncated);
        GRN_TIME_SET(ctx_, &value_, time);
      }
      break;
    case UNSUPPORTED_TYPE:
      // Should not be occurred.
      DBUG_PRINT("error",
                 ("mroonga: append_const_item: unsupported type: <%d> "
                  "This case should not be occurred.",
                  field_type));
      grn_obj_reinit(ctx_, &value_, GRN_DB_VOID, 0);
      break;
    }
    grn_expr_append_const(ctx_, expression, &value_, GRN_OP_PUSH, 1);

    DBUG_VOID_RETURN;
  }
Example #7
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;
}
Example #8
0
String FormatProgress(__int64 cb, __int64 total)
{
  __int64 n=total;
  int pw=0;
  __int64 div=1;
  while (n > 999999) { div*=1024; n/=1024; pw++; }
  String un;
  switch (pw) 
  {
    case 0: un=LOC("Engine.Bytes"); break;
    case 1: un=LOC("Engine.Kb"); break;
    case 2: un=LOC("Engine.Mb"); break;
    case 3: un=LOC("Engine.Gb"); break;
    case 4: un=LOC("Engine.Tb"); break;
    case 5: un=LOC("Engine.Pb"); break;
  }
  return Format(L"%s %s %s %s [%d%%]", FormatNum(cb/div).ptr(), LOC("Engine.Of").ptr(), 
                FormatNum(total/div).ptr(), un.ptr(), (int)(total?(float)cb/total*100:0));
}
Example #9
0
String FormatSpeed(__int64 cb)
{
  __int64 n=cb;
  int pw=0;
  __int64 div=1;
  while (n>=100000) { div*=1024; n/=1024; pw++; }
  String un;
  switch (pw) 
  {
    case 0: un=LOC("Engine.Bytes"); break;
    case 1: un=LOC("Engine.Kb"); break;
    case 2: un=LOC("Engine.Mb"); break;
    case 3: un=LOC("Engine.Gb"); break;
    case 4: un=LOC("Engine.Tb"); break;
    case 5: un=LOC("Engine.Pb"); break;
  }

  return Format(L"%s %s/%s", FormatNum(cb/div).ptr(), un.ptr(), LOC("Engine.Sec").ptr());
}
//----------------------------------------------------------------------------//
bool MinibidiVisualMapping::reorderFromLogicalToVisual(const String& logical,
                                                       String& visual,
                                                       StrIndexList& l2v,
                                                       StrIndexList& v2l) const
{
    visual = logical;

    if (logical.length() <= 1)
        return true;

    l2v.resize(logical.length());
    v2l.resize(logical.length());

    doBidi(visual.ptr(), static_cast<int>(logical.length()),
           true, false,
           &v2l[0], &l2v[0]);

    return true;
}
Example #11
0
bool ShaderMaterial::_get(const StringName& p_name,Variant &r_ret) const {


	if (p_name==SceneStringNames::get_singleton()->shader_shader) {

		r_ret=get_shader();
		return true;
	} else {

		String n = p_name;
		if (n.begins_with("param/")) {
			r_ret=VisualServer::get_singleton()->material_get_param(material,String(n.ptr()+6));
			return true;
		}

	}


	return false;
}
    bool operator==(const String& other) const
    {
      if ( empty() && other.empty() )
        return true;
      if ( empty() && !other.empty() )
        return false;
      if ( !empty() && other.empty() )
        return false;

      createData();

      if (mString == other.mString)
        return true;
      else
      if ( other.length() == length() )
      {
        return memcmp( ptr(), other.ptr(), sizeof(wchar_t)*length() ) == 0;
      }
      else
        return false;
    }
Example #13
0
Error JSON::parse(const String& p_json,Dictionary& 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;
	int line=0;
	String aux_key;

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

	if (token.type!=TK_CURLY_BRACKET_OPEN) {

		r_err_str="Expected '{'";
		return ERR_PARSE_ERROR;
	}

	return _parse_object(r_ret,str,idx,len,r_err_line,r_err_str);

}
//-----------------------------------------------------------------------------
void Win32Context::setWindowTitle(const String& title)
{
    if (hwnd())
        SetWindowText(hwnd(), (wchar_t*)title.ptr());
}
Example #15
0
void FWError(const String & s)
{
    FWError(s.ptr());
}
Example #16
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);
  }
}
Example #17
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);
  }
}
//-----------------------------------------------------------------------------
void DiskDirectory::listFiles(std::vector<String>& files, bool append) const
{
  if (!append)
    files.clear();
  if (path().empty())
  {
    Log::error( "VirtualDirectory::path() must not be empty!\n" );
    return;
  }
  #if defined(VL_PLATFORM_WINDOWS)
    WIN32_FIND_DATA FindFileData;
    memset( &FindFileData, 0, sizeof(FindFileData) );
    String wild = path() + "/*";
    HANDLE hFind = FindFirstFile( (wchar_t*)wild.ptr(), &FindFileData );
    if( hFind == INVALID_HANDLE_VALUE )
    {
      Log::error( Say("Cannot open directory '%s' for file listing.\n") << path() );
    }
    else
    {
      do
      {
        if ( (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 )
        {
          String name;
          name = FindFileData.cFileName;
          // the paths are relative
          files.push_back( path() + name );
        }
      } while( FindNextFile(hFind, &FindFileData) != 0 );

      DWORD dwError = GetLastError();
      FindClose(hFind);
      if (dwError != ERROR_NO_MORE_FILES)
      {
        // do nothing
        // printf ("FindNextFile error. Error is %u\n", dwError);
      }
    }
  #elif defined(__GNUG__)
    std::vector<unsigned char> utf8;
    path().toUTF8( utf8, false );
    struct dirent64 dirp;
    struct dirent64* dirp2;
    DIR* dp = opendir((char*)&utf8[0]);
    if(dp != NULL)
    {
      while(readdir64_r(dp, &dirp, &dirp2) == 0 && dirp2 != NULL)
      {
        String name = dirp.d_name;
        if (name == ".." || name == ".")
          continue;

        name = path() + name;
        // whatever is not a directory is a file for us
        name.toUTF8( utf8, false );
        DIR* is_dir = opendir((char*)&utf8[0]);
        if (is_dir)
          closedir(is_dir);
        // 4  = directory
        // 8  = file
        // 10 = file or directory link
        // to discover directory links you can try to open them with opendir()
        // if (dirp.d_type == 4 )
        if (!is_dir)
          files.push_back( name );
      }
      closedir(dp);
    }
    else
      Log::error( Say("Cannot open directory '%s' for file listing.\n") << path() );
  #endif
}
Example #19
0
void TextBox::setText(String t)
{
  txt_len = t.len();
  strcpy(&txt[0], t.ptr());
}