Skip to content
Commits on Source (3)
  • gambas's avatar
    Remove the Connection.TimeZone property, it is not used yet. · 029f3d35
    gambas authored
    [GB.DB]
    * NEW: Remove the Connection.TimeZone property, it is not used yet.
    029f3d35
  • gambas's avatar
    ScrollView: Fix a possible infinite loop in contents arrangement routine. · 4bf287a4
    gambas authored
    [GB.GUI.BASE]
    * BUG: ScrollView: Fix a possible infinite loop in contents arrangement routine.
    4bf287a4
  • gambas's avatar
    String value can be used like object. · 737b77c3
    gambas authored
    [INTERPRETER]
    * NEW: String value can be used like object.
    * NEW: String[X] returns the X-th character of the string, 0 being the first one.
    * NEW: String[X, N] returns N characters from the position X, 0 being the first one. IF N is strictly negative, then all characters from the position X, except the last N characters are returned.
    * NEW: String.Len returns the length of the string.
    
    [COMPILER]
    * NEW: Allow the [] operator to be applied to a string.
    737b77c3
......@@ -43,6 +43,10 @@ Private Sub AutoResizeContents()
Dim W, H As Integer
Dim hChild As Control
Dim iSaveArr As Integer
If Object.IsLocked($hCont) Then Return
'Debug Me.Name;; System.Backtrace.Join(" ")
Object.Lock($hCont)
......@@ -75,10 +79,13 @@ Private Sub AutoResizeContents()
W = Max(Me.ClientW, W)
H = Max(Me.ClientH, H)
$hCont.Resize(W, H)
iSaveArr = $hCont.Arrangement
$hCont.Arrangement = Arrange.None
$hCont.Arrangement = iSaveArr
If $hCont.W <> W Or If $hCont.H <> H Then
$hCont.Resize(W, H)
iSaveArr = $hCont.Arrangement
$hCont.Arrangement = Arrange.None
$hCont.Arrangement = iSaveArr
Endif
Object.Unlock($hCont)
End
......
......@@ -431,6 +431,7 @@ static void trans_operation(short op, short nparam, PATTERN previous)
case T_OBJECT:
case T_VARIANT:
case T_STRUCT:
case T_STRING:
break;
default:
......
......@@ -60,7 +60,7 @@ const uchar STRING_char_length[256] =
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
};
/***************************************************************************/
//-----------------------------------------------------------------------------
static int utf8_get_length(const char *sstr, int len)
{
......@@ -187,8 +187,7 @@ int COMMON_get_unicode_char()
return (int)uc;
}
/***************************************************************************/
//-----------------------------------------------------------------------------
char *STRING_utf8_current = NULL;
static const char *_utf8_current_start = NULL;
......@@ -354,8 +353,7 @@ __CALC_POS:
return pos;
}
/***************************************************************************/
//-----------------------------------------------------------------------------
static int byte_to_index(const char *str, int len, int byte)
{
......@@ -883,9 +881,81 @@ _INVALID:
END_METHOD
#endif
//-----------------------------------------------------------------------------
BEGIN_PROPERTY(BoxedString_Len)
VALUE *val = &SP[-1];
VARIANT_undo(val);
int len = val->_string.len;
RELEASE_STRING(val);
GB_ReturnInteger(len);
GB_DESC NATIVE_String[] =
END_PROPERTY
void BoxedString_get(ushort code)
{
int start;
int len;
bool null;
code++;
SUBR_ENTER();
null = SUBR_check_string(PARAM);
VALUE_conv_integer(&PARAM[1]);
start = PARAM[1]._integer.value;
if (start < 0)
THROW(E_ARG);
if (null)
goto _SUBR_MID_FIN;
if (start >= PARAM->_string.len)
{
VOID_STRING(PARAM);
goto _SUBR_MID_FIN;
}
if (NPARAM == 2)
len = 1;
else
{
VALUE_conv_integer(&PARAM[2]);
len = PARAM[2]._integer.value;
}
if (len < 0)
len = Max(0, PARAM->_string.len - start + len);
len = MinMax(len, 0, PARAM->_string.len - start);
if (len == 0)
{
RELEASE_STRING(PARAM);
PARAM->_string.addr = NULL;
PARAM->_string.start = 0;
}
else
PARAM->_string.start += start;
PARAM->_string.len = len;
_SUBR_MID_FIN:
SP -= NPARAM;
SP++;
}
#endif // GBX_INFO
//-----------------------------------------------------------------------------
GB_DESC StringDesc[] =
{
GB_DECLARE_STATIC("String"),
......@@ -926,3 +996,51 @@ GB_DESC NATIVE_String[] =
GB_END_DECLARE
};
//-----------------------------------------------------------------------------
GB_DESC BoxedStringDesc[] =
{
GB_DECLARE_STATIC("_BoxedString"),
GB_STATIC_PROPERTY_READ("Len", "i", BoxedString_Len),
GB_STATIC_FAST_METHOD("_get", "s", BoxedString_get, "(Start)i[(Length)i]"),
//GB_STATIC_FAST_METHOD("_get", "s", _String_get, "(Start)i[(Length)i]"),
/*GB_STATIC_FAST_METHOD("Mid", "s", _String_Mid, "(String)s(Start)i[(Length)i]"),
GB_STATIC_FAST_METHOD("Mid$", "s", _String_Mid, "(String)s(Start)i[(Length)i]"),
GB_STATIC_FAST_METHOD("Left", "s", _String_Left, "(String)s[(Length)i]"),
GB_STATIC_FAST_METHOD("Left$", "s", _String_Left, "(String)s[(Length)i]"),
GB_STATIC_FAST_METHOD("Right", "s", _String_Right, "(String)s[(Length)i]"),
GB_STATIC_FAST_METHOD("Right$", "s", _String_Right, "(String)s[(Length)i]"),
GB_STATIC_METHOD("Upper", "s", String_Upper, "(String)s"),
GB_STATIC_METHOD("Upper$", "s", String_Upper, "(String)s"),
GB_STATIC_METHOD("UCase", "s", String_Upper, "(String)s"),
GB_STATIC_METHOD("UCase$", "s", String_Upper, "(String)s"),
GB_STATIC_METHOD("UCaseFirst", "s", String_UCaseFirst, "(String)s"),
GB_STATIC_METHOD("UCaseFirst$", "s", String_UCaseFirst, "(String)s"),
GB_STATIC_METHOD("Lower", "s", String_Lower, "(String)s"),
GB_STATIC_METHOD("Lower$", "s", String_Lower, "(String)s"),
GB_STATIC_METHOD("LCase", "s", String_Lower, "(String)s"),
GB_STATIC_METHOD("LCase$", "s", String_Lower, "(String)s"),
GB_STATIC_METHOD("InStr", "i", String_Instr, "(String)s(Pattern)s[(From)i(Mode)i]"),
GB_STATIC_METHOD("RInStr", "i", String_RInstr, "(String)s(Pattern)s[(From)i(Mode)i]"),
GB_STATIC_METHOD("Comp", "i", String_Comp, "(String)s(String2)s[(Mode)i]"),
GB_STATIC_METHOD("Byte", "i", String_Pos, "(String)s(Index)i"),
GB_STATIC_METHOD("Pos", "i", String_Pos, "(String)s(Index)i"),
GB_STATIC_METHOD("Index", "i", String_Index, "(String)s(Byte)i"),
GB_STATIC_METHOD("Chr", "s", String_Chr, "(Unicode)i"),
GB_STATIC_METHOD("Chr$", "s", String_Chr, "(Unicode)i"),
GB_STATIC_METHOD("Code", "i", String_Code, "(String)s[(Index)i]"),
GB_STATIC_METHOD("IsValid", "b", String_IsValid, "(String)s"),*/
GB_END_DECLARE
};
......@@ -28,7 +28,9 @@
#ifndef __GBX_C_STRING_C
EXTERN GB_DESC NATIVE_String[];
EXTERN GB_DESC StringDesc[];
EXTERN GB_DESC BoxedStringDesc[];
EXTERN const char STRING_char_length[];
#endif
......@@ -43,4 +45,6 @@ uint STRING_utf8_to_unicode(const char *sstr, int len);
int COMMON_get_unicode_char();
void BoxedString_get(ushort code);
#endif
......@@ -373,7 +373,8 @@ typedef
enum {
CQA_NONE = 0,
CQA_ARRAY = 1,
CQA_COLLECTION = 2
CQA_COLLECTION = 2,
CQA_STRING = 3
}
CLASS_QUICK_ARRAY;
......@@ -411,6 +412,7 @@ EXTERN CLASS *CLASS_Process;
EXTERN CLASS *CLASS_Component;
EXTERN CLASS *CLASS_Observer;
EXTERN CLASS *CLASS_Timer;
EXTERN CLASS *CLASS_BoxedString;
EXTERN CLASS *CLASS_BooleanArray;
EXTERN CLASS *CLASS_ByteArray;
......
......@@ -60,6 +60,7 @@ CLASS *CLASS_Process = NULL;
CLASS *CLASS_Component = NULL;
CLASS *CLASS_Observer = NULL;
CLASS *CLASS_Timer = NULL;
CLASS *CLASS_BoxedString = NULL;
CLASS *CLASS_Array = NULL;
CLASS *CLASS_BooleanArray = NULL;
......@@ -113,7 +114,8 @@ static const CLASS_INIT init_list[] =
{ NATIVE_System, NULL },
{ NATIVE_Jit, NULL },
{ NATIVE_User, NULL },
{ NATIVE_String, NULL },
{ StringDesc, NULL },
{ BoxedStringDesc, &CLASS_BoxedString, CQA_STRING },
{ TaskDesc, NULL },
{ NATIVE_Timer, &CLASS_Timer },
{ NATIVE_Observer, &CLASS_Observer },
......
......@@ -1465,6 +1465,11 @@ CLASS *EXEC_object_variant(VALUE *val, OBJECT **pobject)
class = object->class;
goto __CHECK;
}
else if (val->_variant.vtype == T_STRING || val->_variant.vtype == T_CSTRING)
{
*pobject = NULL;
return CLASS_BoxedString;
}
else
goto __ERROR;
......@@ -1492,7 +1497,7 @@ bool EXEC_object_other(VALUE *val, CLASS **pclass, OBJECT **pobject)
{
static const void *jump[] = {
&&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR,
&&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__FUNCTION, &&__CLASS, &&__NULL,
&&__STRING, &&__CSTRING, &&__ERROR, &&__ERROR, &&__FUNCTION, &&__CLASS, &&__NULL,
&&__OBJECT,
};
......@@ -1549,6 +1554,13 @@ __OBJECT:
defined = FALSE;
goto __CHECK;
__STRING:
__CSTRING:
*pclass = CLASS_BoxedString;
*pobject = NULL;
return TRUE;
__ERROR:
......@@ -1650,10 +1662,18 @@ bool EXEC_special(int special, CLASS *class, void *object, int nparam, bool drop
if (FUNCTION_is_native(&desc->method))
{
EXEC.desc = &desc->method;
EXEC.use_stack = FALSE;
EXEC.native = TRUE;
EXEC_native();
if (desc->method.subr)
{
((EXEC_FUNC_CODE)(EXEC.class->table[index].desc->method.exec))(nparam);
}
else
{
EXEC.desc = &desc->method;
EXEC.use_stack = FALSE;
EXEC.native = TRUE;
EXEC_native();
}
if (drop)
POP();
}
......
......@@ -43,6 +43,7 @@
#include "gbx_subr.h"
#include "gbx_math.h"
#include "gbx_c_array.h"
#include "gbx_c_string.h"
#include "gbx_struct.h"
#include "gbx_variant.h"
#include "gbx_jit.h"
......@@ -62,6 +63,7 @@
#define GET_XX() ((signed char)code)
#define GET_UX() ((unsigned char)code)
#define GET_3X() (code & 0x3F)
#define GET_0X() (code & 0xF)
#define TEST_XX() (code & 1)
static void my_VALUE_class_read(CLASS *class, VALUE *value, char *addr, CTYPE ctype, void *ref);
......@@ -3527,7 +3529,7 @@ void EXEC_push_array(ushort code)
&&__PUSH_GENERIC, &&__PUSH_GENERIC, &&__PUSH_GENERIC, &&__PUSH_GENERIC,
&&__PUSH_ARRAY, &&__PUSH_ARRAY, &&__PUSH_ARRAY, &&__PUSH_ARRAY,
&&__PUSH_NATIVE_ARRAY, NULL, &&__PUSH_NATIVE_ARRAY_SIMPLE, &&__PUSH_NATIVE_ARRAY_SIMPLE,
&&__PUSH_NATIVE_COLLECTION, &&__PUSH_NATIVE_ARRAY_INTEGER, &&__PUSH_NATIVE_ARRAY_FLOAT, NULL
&&__PUSH_NATIVE_COLLECTION, &&__PUSH_NATIVE_ARRAY_INTEGER, &&__PUSH_NATIVE_ARRAY_FLOAT, &&__PUSH_NATIVE_STRING
};
CLASS *class;
......@@ -3550,6 +3552,19 @@ __PUSH_GENERIC:
defined = EXEC_object(val, &class, &object);
if (class->quick_array == CQA_STRING)
{
if (np < 1)
THROW(E_NEPARAM);
else if (np > 2)
THROW(E_TMPARAM);
if (defined)
*PC = (*PC & 0xFF00) | (0xF1 + np);
goto __PUSH_NATIVE_STRING;
}
fast = 0x41 + np;
if (defined)
......@@ -3597,7 +3612,7 @@ __PUSH_GENERIC:
}
}
}
*PC = (*PC & 0xFF00) | fast;
goto __PUSH_ARRAY_2;
......@@ -3631,6 +3646,11 @@ __PUSH_NATIVE_COLLECTION:
RELEASE_STRING(&val[1]);
goto __PUSH_NATIVE_END;
__PUSH_NATIVE_STRING:
BoxedString_get(GET_0X() - 1);
return;
__PUSH_NATIVE_ARRAY_SIMPLE:
val = &SP[-2];
......
......@@ -263,6 +263,7 @@ BEGIN_PROPERTY(Connection_Timeout)
END_PROPERTY
#if 0
BEGIN_PROPERTY(Connection_Timezone)
if (READ_PROPERTY)
......@@ -271,6 +272,7 @@ BEGIN_PROPERTY(Connection_Timezone)
THIS->db.timezone = VPROP(GB_INTEGER);
END_PROPERTY
#endif
BEGIN_PROPERTY(CCONNECTION_opened)
......@@ -783,7 +785,7 @@ GB_DESC CConnectionDesc[] =
GB_PROPERTY("Name", "s", CCONNECTION_name),
GB_PROPERTY("Port", "s", CCONNECTION_port),
GB_PROPERTY("Timeout", "i", Connection_Timeout),
GB_PROPERTY("Timezone", "i", Connection_Timezone),
//GB_PROPERTY("Timezone", "i", Connection_Timezone),
GB_PROPERTY_READ("Charset", "s", CCONNECTION_charset),
GB_PROPERTY_READ("Version", "i", CCONNECTION_version),
GB_PROPERTY_READ("Opened", "b", CCONNECTION_opened),
......