1 /* Copyright (c) 2004-2005 Nokia. All rights reserved. */
3 /* The PerlUtil class is licensed under the same terms as Perl itself. */
5 /* See PerlUtil.pod for documentation. */
16 EXPORT_C SV* PerlUtil::newSvPVfromTDesC8(const TDesC8& aDesC8) {
18 return newSVpvn((const char *)aDesC8.Ptr(), aDesC8.Size());
21 EXPORT_C void PerlUtil::setSvPVfromTDesC8(SV* sv, const TDesC8& aDesC8) {
23 sv_setpvn(sv, (const char *)aDesC8.Ptr(), aDesC8.Size());
26 EXPORT_C HBufC8* PerlUtil::newHBufC8fromSvPV(SV* sv) {
28 return PerlUtil::newHBufC8fromPVn((const U8 *)SvPV_nolen(sv), SvLEN(sv));
31 EXPORT_C void PerlUtil::setTDes8fromSvPV(TDes8& aDes8, SV* sv) {
33 PerlUtil::setTDes8fromPVn(aDes8, (const U8 *)SvPV_nolen(sv), SvLEN(sv));
36 EXPORT_C SV* PerlUtil::newSvPVfromTDesC16(const TDesC16& aDesC16) {
39 HBufC8* hBuf8 = HBufC8::New(aDesC16.Length() * 3);
42 TPtr8 aPtr8(hBuf8->Des());
43 CnvUtfConverter::ConvertFromUnicodeToUtf8(aPtr8, aDesC16);
44 sv = newSVpvn((const char *)(hBuf8->Ptr()), hBuf8->Size());
53 EXPORT_C void PerlUtil::setSvPVfromTDesC16(SV* sv, const TDesC16& aDesC16) {
55 HBufC8* hBuf8 = HBufC8::New(aDesC16.Length() * 3);
58 TPtr8 aPtr8(hBuf8->Des());
59 CnvUtfConverter::ConvertFromUnicodeToUtf8(aPtr8, aDesC16);
60 sv_setpvn(sv, (const char *)(hBuf8->Ptr()), hBuf8->Size());
67 EXPORT_C HBufC16* PerlUtil::newHBufC16fromSvPV(SV* sv) {
69 return PerlUtil::newHBufC16fromPVn((const U8 *)SvPV_nolen(sv), SvLEN(sv), SvUTF8(sv));
72 void PerlUtil::setTDes16fromSvPV(TDes16& aDes16, SV* sv) {
74 PerlUtil::setTDes16fromPVn(aDes16, (const U8 *)SvPV_nolen(sv), SvLEN(sv), SvUTF8(sv));
77 EXPORT_C HBufC8* PerlUtil::newHBufC8fromPVn(const U8* s, STRLEN n) {
78 HBufC8* aBuf8 = HBufC8::New(n);
80 TPtr8 ptr8 = aBuf8->Des();
86 EXPORT_C void PerlUtil::setTDes8fromPVn(TDes8& aDes8, const U8* s, STRLEN n) {
87 // TODO: grow aDes8 if needed
91 EXPORT_C HBufC16* PerlUtil::newHBufC16fromPVn(const U8 *s, STRLEN n, bool utf8) {
92 HBufC16 *hBuf16 = HBufC16::New(n); // overallocate
96 TPtr16 aPtr16(hBuf16->Des());
98 CnvUtfConverter::ConvertToUnicodeFromUtf8(aPtr16, aPtrC8);
101 hBuf16->Des().Copy(aPtrC8);
108 EXPORT_C void PerlUtil::setTDes16fromPVn(TDes16& aDes16, const U8 *s, STRLEN n, bool utf8) {
109 // TODO: grow aDes16 if needed
112 CnvUtfConverter::ConvertToUnicodeFromUtf8(aDes16, aPtrC8);