aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2019-12-25 18:17:23 +0100
committerMarvin W <git@larma.de>2019-12-25 19:56:51 +0100
commit11a118d53d4ef9c27c096b8c9c15dfeb4cb41e03 (patch)
treee2c1fe497ba6eefec909f2a0e839c5feef4dd0bd /xmpp-vala/src
parent4197b589d02f284a4ecf2a6d1bcb8c60e0e83861 (diff)
downloaddino-11a118d53d4ef9c27c096b8c9c15dfeb4cb41e03.tar.gz
dino-11a118d53d4ef9c27c096b8c9c15dfeb4cb41e03.zip
Fix issues in ICU usage
Diffstat (limited to 'xmpp-vala/src')
-rw-r--r--xmpp-vala/src/module/jid.vala14
1 files changed, 8 insertions, 6 deletions
diff --git a/xmpp-vala/src/module/jid.vala b/xmpp-vala/src/module/jid.vala
index f8d09e7e..d5dea870 100644
--- a/xmpp-vala/src/module/jid.vala
+++ b/xmpp-vala/src/module/jid.vala
@@ -89,21 +89,23 @@ public class Jid {
private static string? prepare(string? src, ICU.PrepType type, bool strict = false) throws InvalidJidError {
if (src == null) return src;
try {
+ ICU.ParseError error;
ICU.ErrorCode status = ICU.ErrorCode.ZERO_ERROR;
ICU.PrepProfile profile = ICU.PrepProfile.openByType(type, ref status);
- long src16_length = 0;
- string16 src16 = src.to_utf16(-1, null, out src16_length);
- ICU.Char[] dest16 = new ICU.Char[src16_length * 2];
- ICU.ParseError error;
- long dest16_length = profile.prepare((ICU.Char*) src16, (int32) src16_length, dest16, dest16.length, strict ? ICU.PrepOptions.DEFAULT : ICU.PrepOptions.ALLOW_UNASSIGNED, out error, ref status);
+ ICU.String src16 = ICU.String.from_string(src);
+ int32 dest16_capacity = src16.len() * 2 + 1;
+ ICU.String dest16 = ICU.String.alloc(dest16_capacity);
+ long dest16_length = profile.prepare(src16, src16.len(), dest16, dest16_capacity, strict ? ICU.PrepOptions.DEFAULT : ICU.PrepOptions.ALLOW_UNASSIGNED, out error, ref status);
if (status == ICU.ErrorCode.INVALID_CHAR_FOUND) {
throw new InvalidJidError.INVALID_CHAR("Found invalid character");
+ } else if (status == ICU.ErrorCode.STRINGPREP_PROHIBITED_ERROR) {
+ throw new InvalidJidError.INVALID_CHAR("Found prohibited character");
} else if (status != ICU.ErrorCode.ZERO_ERROR) {
throw new InvalidJidError.UNKNOWN(@"Unknown error: $(status.errorName())");
} else if (dest16_length < 0) {
throw new InvalidJidError.UNKNOWN("Unknown error");
}
- return ((string16) dest16).to_utf8(dest16_length, null, null);
+ return dest16.to_string();
} catch (ConvertError e) {
throw new InvalidJidError.INVALID_CHAR(@"Conversion error: $(e.message)");
}