@@ -120,40 +120,6 @@ from_binary(J) when is_binary(J), byte_size(J) < ?XMPP_JID_SIZE_LIMIT ->
120
120
from_binary (_ ) ->
121
121
error .
122
122
123
- binary_to_jid1 (_ , <<$@ , _J /binary >>, 0 ) ->
124
- error ;
125
- binary_to_jid1 (Jid , <<$@ , J /binary >>, N ) ->
126
- binary_to_jid2 (Jid , J , N , 0 );
127
- binary_to_jid1 (_ , <<$/ , _J /binary >>, 0 ) ->
128
- error ;
129
- binary_to_jid1 (Jid , <<$/ , _ /binary >>, N ) ->
130
- {<<>>,
131
- erlang :binary_part (Jid , {0 , N }),
132
- erlang :binary_part (Jid , {N + 1 , byte_size (Jid ) - N - 1 })};
133
- binary_to_jid1 (Jid , <<_C , J /binary >>, N ) ->
134
- binary_to_jid1 (Jid , J , N + 1 );
135
- binary_to_jid1 (_ , <<>>, 0 ) ->
136
- error ;
137
- binary_to_jid1 (J , <<>>, _ ) ->
138
- {<<>>, J , <<>>}.
139
-
140
- binary_to_jid2 (_ , <<$@ , _J /binary >>, _N , _S ) ->
141
- error ;
142
- binary_to_jid2 (_ , <<$/ , _J /binary >>, _N , 0 ) ->
143
- error ;
144
- binary_to_jid2 (Jid , <<$/ , _ /binary >>, N , S ) ->
145
- {erlang :binary_part (Jid , {0 , N }),
146
- erlang :binary_part (Jid , {N + 1 , S }),
147
- erlang :binary_part (Jid , {N + S + 2 , byte_size (Jid ) - N - S - 2 })};
148
- binary_to_jid2 (Jid , <<_C , J /binary >>, N , S ) ->
149
- binary_to_jid2 (Jid , J , N , S + 1 );
150
- binary_to_jid2 (_ , <<>>, _N , 0 ) ->
151
- error ;
152
- binary_to_jid2 (Jid , <<>>, N , S ) ->
153
- {erlang :binary_part (Jid , {0 , N }),
154
- erlang :binary_part (Jid , {N + 1 , S }),
155
- <<>>}.
156
-
157
123
% % @doc Parses a binary and returns a jid record or an error, but without normalisation of the parts
158
124
-spec from_binary_noprep (binary ()) -> jid () | error .
159
125
from_binary_noprep (J ) when is_binary (J ), byte_size (J ) < ? XMPP_JID_SIZE_LIMIT ->
@@ -338,3 +304,116 @@ binary_to_bare(JID) when is_binary(JID) ->
338
304
-spec str_tolower (iodata ()) -> binary () | error .
339
305
str_tolower (Val ) when is_binary (Val ); is_list (Val ) ->
340
306
stringprep :tolower (Val ).
307
+
308
+ % %%%% Helpers
309
+ binary_to_jid1 (_ , <<>>, 0 ) ->
310
+ error ;
311
+ binary_to_jid1 (J , <<>>, _ ) ->
312
+ {<<>>, J , <<>>};
313
+ binary_to_jid1 (_ , <<$@ , _J /binary >>, 0 ) ->
314
+ error ;
315
+ binary_to_jid1 (Jid , <<$@ , J /binary >>, N ) ->
316
+ binary_to_jid2 (Jid , J , N , 0 );
317
+ binary_to_jid1 (Jid , <<_ , $@ , J /binary >>, N ) ->
318
+ binary_to_jid2 (Jid , J , N + 1 , 0 );
319
+ binary_to_jid1 (Jid , <<_ , _ , $@ , J /binary >>, N ) ->
320
+ binary_to_jid2 (Jid , J , N + 2 , 0 );
321
+ binary_to_jid1 (Jid , <<_ , _ , _ , $@ , J /binary >>, N ) ->
322
+ binary_to_jid2 (Jid , J , N + 3 , 0 );
323
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , $@ , J /binary >>, N ) ->
324
+ binary_to_jid2 (Jid , J , N + 4 , 0 );
325
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , $@ , J /binary >>, N ) ->
326
+ binary_to_jid2 (Jid , J , N + 5 , 0 );
327
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , _ , $@ , J /binary >>, N ) ->
328
+ binary_to_jid2 (Jid , J , N + 6 , 0 );
329
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , _ , _ , $@ , J /binary >>, N ) ->
330
+ binary_to_jid2 (Jid , J , N + 7 , 0 );
331
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , _ , _ , _ , $@ , J /binary >>, N ) ->
332
+ binary_to_jid2 (Jid , J , N + 8 , 0 );
333
+ binary_to_jid1 (_ , <<$/ , _J /binary >>, 0 ) ->
334
+ error ;
335
+ binary_to_jid1 (Jid , <<$/ , _ /binary >>, N ) ->
336
+ {<<>>,
337
+ erlang :binary_part (Jid , {0 , N }),
338
+ erlang :binary_part (Jid , {N + 1 , byte_size (Jid ) - N - 1 })};
339
+ binary_to_jid1 (Jid , <<_ , $/ , _ /binary >>, N ) ->
340
+ {<<>>,
341
+ erlang :binary_part (Jid , {0 , N + 1 }),
342
+ erlang :binary_part (Jid , {N + 2 , byte_size (Jid ) - N - 2 })};
343
+ binary_to_jid1 (Jid , <<_ , _ , $/ , _ /binary >>, N ) ->
344
+ {<<>>,
345
+ erlang :binary_part (Jid , {0 , N + 2 }),
346
+ erlang :binary_part (Jid , {N + 3 , byte_size (Jid ) - N - 3 })};
347
+ binary_to_jid1 (Jid , <<_ , _ , _ , $/ , _ /binary >>, N ) ->
348
+ {<<>>,
349
+ erlang :binary_part (Jid , {0 , N + 3 }),
350
+ erlang :binary_part (Jid , {N + 4 , byte_size (Jid ) - N - 4 })};
351
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , $/ , _ /binary >>, N ) ->
352
+ {<<>>,
353
+ erlang :binary_part (Jid , {0 , N + 4 }),
354
+ erlang :binary_part (Jid , {N + 5 , byte_size (Jid ) - N - 5 })};
355
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , $/ , _ /binary >>, N ) ->
356
+ {<<>>,
357
+ erlang :binary_part (Jid , {0 , N + 5 }),
358
+ erlang :binary_part (Jid , {N + 6 , byte_size (Jid ) - N - 6 })};
359
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , _ , $/ , _ /binary >>, N ) ->
360
+ {<<>>,
361
+ erlang :binary_part (Jid , {0 , N + 6 }),
362
+ erlang :binary_part (Jid , {N + 7 , byte_size (Jid ) - N - 7 })};
363
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , _ , _ , $/ , _ /binary >>, N ) ->
364
+ {<<>>,
365
+ erlang :binary_part (Jid , {0 , N + 7 }),
366
+ erlang :binary_part (Jid , {N + 8 , byte_size (Jid ) - N - 8 })};
367
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , _ , _ , _ , $/ , _ /binary >>, N ) ->
368
+ {<<>>,
369
+ erlang :binary_part (Jid , {0 , N + 8 }),
370
+ erlang :binary_part (Jid , {N + 9 , byte_size (Jid ) - N - 9 })};
371
+ binary_to_jid1 (Jid , <<_ , _ , _ , _ , _ , _ , _ , _ , J /binary >>, N ) ->
372
+ binary_to_jid1 (Jid , J , N + 8 );
373
+ binary_to_jid1 (Jid , <<_C , J /binary >>, N ) ->
374
+ binary_to_jid1 (Jid , J , N + 1 ).
375
+
376
+ binary_to_jid2 (_ , <<>>, _N , 0 ) ->
377
+ error ;
378
+ binary_to_jid2 (Jid , <<>>, N , S ) ->
379
+ {erlang :binary_part (Jid , {0 , N }),
380
+ erlang :binary_part (Jid , {N + 1 , S }),
381
+ <<>>};
382
+ binary_to_jid2 (_ , <<$/ , _J /binary >>, _N , 0 ) ->
383
+ error ;
384
+ binary_to_jid2 (Jid , <<$/ , _ /binary >>, N , S ) ->
385
+ {erlang :binary_part (Jid , {0 , N }),
386
+ erlang :binary_part (Jid , {N + 1 , S }),
387
+ erlang :binary_part (Jid , {N + S + 2 , byte_size (Jid ) - N - S - 2 })};
388
+ binary_to_jid2 (Jid , <<_ , " /" , _ /binary >>, N , S ) ->
389
+ {erlang :binary_part (Jid , {0 , N }),
390
+ erlang :binary_part (Jid , {N + 1 , S + 1 }),
391
+ erlang :binary_part (Jid , {N + S + 3 , byte_size (Jid ) - N - S - 3 })};
392
+ binary_to_jid2 (Jid , <<_ , _ , " /" , _ /binary >>, N , S ) ->
393
+ {erlang :binary_part (Jid , {0 , N }),
394
+ erlang :binary_part (Jid , {N + 1 , S + 2 }),
395
+ erlang :binary_part (Jid , {N + S + 4 , byte_size (Jid ) - N - S - 4 })};
396
+ binary_to_jid2 (Jid , <<_ , _ , _ , " /" , _ /binary >>, N , S ) ->
397
+ {erlang :binary_part (Jid , {0 , N }),
398
+ erlang :binary_part (Jid , {N + 1 , S + 3 }),
399
+ erlang :binary_part (Jid , {N + S + 5 , byte_size (Jid ) - N - S - 5 })};
400
+ binary_to_jid2 (Jid , <<_ , _ , _ , _ , " /" , _ /binary >>, N , S ) ->
401
+ {erlang :binary_part (Jid , {0 , N }),
402
+ erlang :binary_part (Jid , {N + 1 , S + 4 }),
403
+ erlang :binary_part (Jid , {N + S + 6 , byte_size (Jid ) - N - S - 6 })};
404
+ binary_to_jid2 (Jid , <<_ , _ , _ , _ , _ , " /" , _ /binary >>, N , S ) ->
405
+ {erlang :binary_part (Jid , {0 , N }),
406
+ erlang :binary_part (Jid , {N + 1 , S + 5 }),
407
+ erlang :binary_part (Jid , {N + S + 7 , byte_size (Jid ) - N - S - 7 })};
408
+ binary_to_jid2 (Jid , <<_ , _ , _ , _ , _ , _ , " /" , _ /binary >>, N , S ) ->
409
+ {erlang :binary_part (Jid , {0 , N }),
410
+ erlang :binary_part (Jid , {N + 1 , S + 6 }),
411
+ erlang :binary_part (Jid , {N + S + 8 , byte_size (Jid ) - N - S - 8 })};
412
+ binary_to_jid2 (Jid , <<_ , _ , _ , _ , _ , _ , _ , " /" , _ /binary >>, N , S ) ->
413
+ {erlang :binary_part (Jid , {0 , N }),
414
+ erlang :binary_part (Jid , {N + 1 , S + 7 }),
415
+ erlang :binary_part (Jid , {N + S + 9 , byte_size (Jid ) - N - S - 9 })};
416
+ binary_to_jid2 (Jid , <<_ , _ , _ , _ , _ , _ , _ , _ , J /binary >>, N , S ) ->
417
+ binary_to_jid2 (Jid , J , N , S + 8 );
418
+ binary_to_jid2 (Jid , <<_C , J /binary >>, N , S ) ->
419
+ binary_to_jid2 (Jid , J , N , S + 1 ).
0 commit comments