Re: [ooc-compiler] Deep-copying STRING
Brought to you by:
mva
|
From: Tim T. <ra...@ed...> - 2004-03-16 13:08:26
|
Hello!
> I need to do a deep copy of a variable of type STRING. What's the metho=
d?
> All I can find in the documentation is that STRING is a synonym for
> Object.String.
>=20
> Do I just do:
>=20
> VAR newstring : STRING;
>=20
> NEW (newstring);
> newstring^ :=3D oldstring^;
>=20
> Frank Copeland
Instances of STRING or Object.String are inmutable, so normally there is =
no need to make a copy at all.
If you look at Object.Mod you'll see, that even String.ToString() will=20
return iteself for exactly that reason.
If you really need a copy it looks like you must use ToString16(), call=20
CharsUTF16() on the return value and use the result as parameter for=20
NewString16(). However possibly this does not work because of CharsUTF16 =
being read only, you have to try this.
One could add a Copy (and deep copy) method to Object (and implement=20
them for String). You have to ask Michael if this would be part of the=20
master plan. I fear that there might no simple generic way to implement=20
them (at least for deep copy), so most objects would not implement them. =
This might be OK, or might be not.
--=20
Gru=DF...
Tim.
|