Value FindString(Environment &env, const char *str, const char *sub, int start, bool ignoreCaseFlag, bool reverseFlag, bool listFlag) { do { int len = static_cast<int>(::strlen(str)); if (start < 0) { start += len; if (start < 0) start = 0; } if (start > len) return Value::Nil; } while (0); if (reverseFlag) { const char *p = FindString(str + start, sub, ignoreCaseFlag); if (listFlag) { ValueList valListOrg; for ( ; p != nullptr; p = FindString(p + 1, sub, ignoreCaseFlag)) { valListOrg.push_back(Value(static_cast<Number>(p - str))); } Value result; Object_list *pObjList = result.InitAsList(env); pObjList->Reserve(valListOrg.size()); foreach_reverse (ValueList, pValue, valListOrg) { pObjList->AddFast(*pValue); } pObjList->SetValueType(VTYPE_number); return result; } else {
Gura_ImplementMethod(wx_Pen, GetDashes) { Signal &sig = env.GetSignal(); Object_wx_Pen *pThis = Object_wx_Pen::GetObjectThis(arg); if (pThis->IsInvalid(sig)) return Value::Nil; wxDash *dashes; int rtn = pThis->GetEntity()->GetDashes(&dashes); Value result; Object_list *pObjList = result.InitAsList(env); pObjList->Reserve(rtn); for (int i = 0; i < rtn; i++) { pObjList->Add(Value(dashes[i])); } return ReturnValue(env, arg, result); }
Gura_ImplementMethod(wx_DataObject, GetAllFormats) { Signal &sig = env.GetSignal(); Object_wx_DataObject *pThis = Object_wx_DataObject::GetObjectThis(arg); if (pThis->IsInvalid(sig)) return Value::Nil; wxDataObject::Direction dir = wxDataObject::Get; size_t n = pThis->GetEntity()->GetFormatCount(dir); if (arg.IsValid(0)) dir = static_cast<wxDataObject::Direction>(arg.GetInt(0)); Value rtn; wxDataFormat *formats = new wxDataFormat[n]; pThis->GetEntity()->GetAllFormats(formats, dir); Object_list *pObjList = rtn.InitAsList(env); pObjList->Reserve(n); for (size_t i = 0; i < n; i++) { pObjList->Add(Value(new Object_wx_DataFormat(new wxDataFormat(formats[i]), nullptr, OwnerTrue))); } delete[] formats; return rtn; }
Value Object_interp::ConvFromTclObj(Environment &env, Signal &sig, Tcl_Obj *objPtr) { Tcl_ObjType *typePtr = objPtr->typePtr; if (typePtr == nullptr) { return Value(objPtr->bytes, objPtr->length); } else if (typePtr == ObjType_boolean) { int value; ::Tcl_GetBooleanFromObj(_interp, objPtr, &value); return Value(value? true : false); } else if (typePtr == ObjType_bytearray) { int length; unsigned char *binary = ::Tcl_GetByteArrayFromObj(objPtr, &length); return Value(new Object_binary(env, Binary(reinterpret_cast<char *>(binary), length), true)); } else if (typePtr == ObjType_double) { double value; ::Tcl_GetDoubleFromObj(_interp, objPtr, &value); return Value(value); } else if (typePtr == ObjType_int) { int value; ::Tcl_GetIntFromObj(_interp, objPtr, &value); return Value(value); } else if (typePtr == ObjType_list) { int length; ::Tcl_ListObjLength(_interp, objPtr, &length); Value result; Object_list *pObjList = result.InitAsList(env); pObjList->Reserve(length); for (int i = 0; i < length; i++) { Tcl_Obj *objElemPtr; ::Tcl_ListObjIndex(_interp, objPtr, i, &objElemPtr); pObjList->Add(ConvFromTclObj(env, sig, objElemPtr)); if (sig.IsSignalled()) return Value::Nil; } return result; } else if (typePtr == ObjType_string) { int length; char *value = ::Tcl_GetStringFromObj(objPtr, &length); return Value(value); } return Value(objPtr->bytes, objPtr->length); }