• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

processone / ejabberd / 1296

19 Jan 2026 11:25AM UTC coverage: 33.562% (+0.09%) from 33.468%
1296

push

github

badlop
mod_conversejs: Cosmetic change: sort paths alphabetically

0 of 4 new or added lines in 1 file covered. (0.0%)

11245 existing lines in 174 files now uncovered.

15580 of 46421 relevant lines covered (33.56%)

1074.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

37.29
/src/str.erl
1
%%%----------------------------------------------------------------------
2
%%% File    : str.erl
3
%%% Author  : Evgeniy Khramtsov <ekhramtsov@process-one.net>
4
%%% Purpose : Provide binary string manipulations
5
%%% Created : 23 Feb 2012 by Evgeniy Khramtsov <ekhramtsov@process-one.net>
6
%%%
7
%%%
8
%%% ejabberd, Copyright (C) 2002-2026   ProcessOne
9
%%%
10
%%% This program is free software; you can redistribute it and/or
11
%%% modify it under the terms of the GNU General Public License as
12
%%% published by the Free Software Foundation; either version 2 of the
13
%%% License, or (at your option) any later version.
14
%%%
15
%%% This program is distributed in the hope that it will be useful,
16
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
17
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
%%% General Public License for more details.
19
%%%
20
%%% You should have received a copy of the GNU General Public License along
21
%%% with this program; if not, write to the Free Software Foundation, Inc.,
22
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
%%%
24
%%%----------------------------------------------------------------------
25

26
-module(str).
27

28
-author('ekhramtsov@process-one.net').
29

30
%% API
31
-export([equal/2,
32
         concat/2,
33
         rchr/2,
34
         str/2,
35
         rstr/2,
36
         span/2,
37
         cspan/2,
38
         copies/2,
39
         words/1,
40
         words/2,
41
         sub_word/2,
42
         sub_word/3,
43
         strip/1,
44
         strip/2,
45
         len/1,
46
         tokens/2,
47
         left/2,
48
         left/3,
49
         right/2,
50
         right/3,
51
         centre/2,
52
         centre/3,
53
         sub_string/2,
54
         sub_string/3,
55
         to_upper/1,
56
         join/2,
57
         substr/2,
58
         chr/2,
59
         chars/3,
60
         chars/2,
61
         substr/3,
62
         strip/3,
63
         to_lower/1,
64
         to_float/1,
65
         prefix/2,
66
         suffix/2,
67
         format/2,
68
         to_integer/1,
69
         sha/1,
70
         to_hexlist/1,
71
         translate_and_format/3]).
72

73
%%%===================================================================
74
%%% API
75
%%%===================================================================
76
-spec len(binary()) -> non_neg_integer().
77

78
len(B) ->
UNCOV
79
    byte_size(B).
1,833✔
80

81
-spec equal(binary(), binary()) -> boolean().
82

83
equal(B1, B2) ->
84
    B1 == B2.
×
85

86
-spec concat(binary(), binary()) -> binary().
87

88
concat(B1, B2) ->
89
    <<B1/binary, B2/binary>>.
×
90

91
-spec rchr(binary(), char()) -> non_neg_integer().
92

93
rchr(B, C) ->
94
    string:rchr(binary_to_list(B), C).
×
95

96
-spec str(binary(), binary()) -> non_neg_integer().
97

98
str(B1, B2) ->
99
    case binary:match(B1, B2) of
2✔
100
        {R, _Len} -> R+1;
2✔
101
        _ -> 0
×
102
    end.
103

104
-spec rstr(binary(), binary()) -> non_neg_integer().
105

106
rstr(B1, B2) ->
107
    string:rstr(binary_to_list(B1), binary_to_list(B2)).
×
108

109
-spec span(binary(), binary()) -> non_neg_integer().
110

111
span(B1, B2) ->
112
    string:span(binary_to_list(B1), binary_to_list(B2)).
×
113

114
-spec cspan(binary(), binary()) -> non_neg_integer().
115

116
cspan(B1, B2) ->
117
    string:cspan(binary_to_list(B1), binary_to_list(B2)).
×
118

119
-spec copies(binary(), non_neg_integer()) -> binary().
120

121
copies(B, N) ->
122
    binary:copy(B, N).
329,799✔
123

124
-spec words(binary()) -> pos_integer().
125

126
words(B) ->
127
    string:words(binary_to_list(B)).
×
128

129
-spec words(binary(), char()) -> pos_integer().
130

131
words(B, C) ->
132
    string:words(binary_to_list(B), C).
×
133

134
-spec sub_word(binary(), integer()) -> binary().
135

136
sub_word(B, N) ->
137
    iolist_to_binary(string:sub_word(binary_to_list(B), N)).
×
138

139
-spec sub_word(binary(), integer(), char()) -> binary().
140

141
sub_word(B, N, C) ->
142
    iolist_to_binary(string:sub_word(binary_to_list(B), N, C)).
×
143

144
-spec strip(binary()) -> binary().
145

146
strip(B) ->
147
    iolist_to_binary(string:strip(binary_to_list(B))).
×
148

149
-spec strip(binary(), both | left | right) -> binary().
150

151
strip(B, D) ->
152
    iolist_to_binary(string:strip(binary_to_list(B), D)).
×
153

154
-spec left(binary(), non_neg_integer()) -> binary().
155

156
left(B, N) ->
157
    iolist_to_binary(string:left(binary_to_list(B), N)).
×
158

159
-spec left(binary(), non_neg_integer(), char()) -> binary().
160

161
left(B, N, C) ->
162
    iolist_to_binary(string:left(binary_to_list(B), N, C)).
×
163

164
-spec right(binary(), non_neg_integer()) -> binary().
165

166
right(B, N) ->
167
    iolist_to_binary(string:right(binary_to_list(B), N)).
×
168

169
-spec right(binary(), non_neg_integer(), char()) -> binary().
170

171
right(B, N, C) ->
172
    iolist_to_binary(string:right(binary_to_list(B), N, C)).
×
173

174
-spec centre(binary(), non_neg_integer()) -> binary().
175

176
centre(B, N) ->
177
    iolist_to_binary(string:centre(binary_to_list(B), N)).
×
178

179
-spec centre(binary(), non_neg_integer(), char()) -> binary().
180

181
centre(B, N, C) ->
182
    iolist_to_binary(string:centre(binary_to_list(B), N, C)).
×
183

184
-spec sub_string(binary(), pos_integer()) -> binary().
185

186
sub_string(B, N) ->
187
    iolist_to_binary(string:sub_string(binary_to_list(B), N)).
×
188

189
-spec sub_string(binary(), pos_integer(), pos_integer()) -> binary().
190

191
sub_string(B, S, E) ->
192
    iolist_to_binary(string:sub_string(binary_to_list(B), S, E)).
2✔
193

194
-spec to_upper(binary()) -> binary();
195
              (char()) -> char().
196

197
to_upper(B) when is_binary(B) ->
UNCOV
198
    iolist_to_binary(string:to_upper(binary_to_list(B)));
8✔
199
to_upper(C) ->
200
    string:to_upper(C).
×
201

202
-spec join([binary()], binary() | char()) -> binary().
203

204
join(L, Sep) ->
205
    iolist_to_binary(join_s(L, Sep)).
48,039✔
206

207
-spec substr(binary(), pos_integer()) -> binary().
208

209
substr(B, N) ->
210
    binary_part(B, N-1, byte_size(B)-N+1).
×
211

212
-spec chr(binary(), char()) -> non_neg_integer().
213

214
chr(B, C) ->
215
    string:chr(binary_to_list(B), C).
484✔
216

217
-spec chars(char(), non_neg_integer(), binary()) -> binary().
218

219
chars(C, N, B) ->
220
    iolist_to_binary(string:chars(C, N, binary_to_list(B))).
×
221

222
-spec chars(char(), non_neg_integer()) -> binary().
223

224
chars(C, N) ->
225
    iolist_to_binary(string:chars(C, N)).
×
226

227
-spec substr(binary(), pos_integer(), non_neg_integer()) -> binary().
228

229
substr(B, S, E) ->
230
    binary_part(B, S-1, E).
×
231

232
-spec strip(binary(), both | left | right, char()) -> binary().
233

234
strip(B, D, C) ->
235
    iolist_to_binary(string:strip(binary_to_list(B), D, C)).
8,906✔
236

237
-spec to_lower(binary()) -> binary();
238
              (char()) -> char().
239

240
to_lower(B) when is_binary(B) ->
241
    iolist_to_binary(string:to_lower(binary_to_list(B)));
1,827✔
242
to_lower(C) ->
243
    string:to_lower(C).
×
244

245
-spec tokens(binary(), binary()) -> [binary()].
246

247
tokens(B1, B2) ->
248
    [iolist_to_binary(T) ||
62,101✔
249
        T <- string:tokens(binary_to_list(B1), binary_to_list(B2))].
62,101✔
250

251
-spec to_float(binary()) -> {float(), binary()} | {error, no_float}.
252

253
to_float(B) ->
254
    case string:to_float(binary_to_list(B)) of
×
255
        {error, R} ->
256
            {error, R};
×
257
        {Float, Rest} ->
258
            {Float, iolist_to_binary(Rest)}
×
259
    end.
260

261
-spec to_integer(binary()) -> {integer(), binary()} | {error, no_integer}.
262

263
to_integer(B) ->
264
    case string:to_integer(binary_to_list(B)) of
×
265
        {error, R} ->
266
            {error, R};
×
267
        {Int, Rest} ->
268
            {Int, iolist_to_binary(Rest)}
×
269
    end.
270

271
-spec prefix(binary(), binary()) -> boolean().
272

273
prefix(Prefix, B) ->
274
    Size = byte_size(Prefix),
×
275
    case B of
×
276
        <<Prefix:Size/binary, _/binary>> ->
277
            true;
×
278
        _ ->
279
            false
×
280
    end.
281

282
-spec suffix(binary(), binary()) -> boolean().
283

284
suffix(B1, B2) ->
UNCOV
285
    lists:suffix(binary_to_list(B1), binary_to_list(B2)).
163✔
286

287
-spec format(io:format(), list()) -> binary().
288

289
format(Format, Args) ->
UNCOV
290
    unicode:characters_to_binary(io_lib:format(Format, Args)).
215✔
291

292
-spec translate_and_format(binary(), binary(), list()) -> binary().
293

294
translate_and_format(Lang, Format, Args) ->
UNCOV
295
    format(unicode:characters_to_list(translate:translate(Lang, Format)), Args).
82✔
296

297

298
-spec sha(iodata()) -> binary().
299

300
sha(Text) ->
301
    Bin = crypto:hash(sha, Text),
3,463✔
302
    to_hexlist(Bin).
3,463✔
303

304
-spec to_hexlist(binary()) -> binary().
305

306
to_hexlist(S) when is_list(S) ->
307
    to_hexlist(iolist_to_binary(S));
×
308
to_hexlist(Bin) when is_binary(Bin) ->
309
    << <<(digit_to_xchar(N div 16)), (digit_to_xchar(N rem 16))>> || <<N>> <= Bin >>.
3,666✔
310

311
%%%===================================================================
312
%%% Internal functions
313
%%%===================================================================
314
join_s([], _Sep) ->
UNCOV
315
    [];
192✔
316
join_s([H|T], Sep) ->
317
    [H, [[Sep, X] || X <- T]].
47,847✔
318

319
digit_to_xchar(D) when (D >= 0) and (D < 10) -> D + $0;
92,154✔
320
digit_to_xchar(D) -> D + $a - 10.
48,438✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc