1 | package fr.sii.ogham.sms.splitter; | |
2 | ||
3 | /** | |
4 | * Every character present in base character table count as 1 octet. | |
5 | * | |
6 | * Every character present in extended character table count as 2 octets (escape | |
7 | * character followed by extension character). | |
8 | * | |
9 | * @author Aurélien Baudet | |
10 | */ | |
11 | public class GsmBasicCharsetExtensionTableCounter implements LengthCounter { | |
12 | private static final int MAXIMUM_SPLIT_SEGMENT_LENGTH = 153; | |
13 | private static final char[] EXT_CHARS = { '\f', '^', '{', '}', '\\', '[', '~', ']', '|', '\u20ac' }; | |
14 | ||
15 | /** | |
16 | * If extended characters are found in the string, each character must be | |
17 | * count as 2 characters. As they are already present in the original | |
18 | * string, add the number of extended characters to original string length. | |
19 | */ | |
20 | @Override | |
21 | public int count(String str) { | |
22 | int originalLength = str.length(); | |
23 | int extendedChars = countExtendedChars(str); | |
24 | // There is a edge case where the whole message can't fit in a single | |
25 | // segment, contains extended characters only and the segments are full. | |
26 | // | |
27 | // As the message can't fit in one segment so it must be | |
28 | // split in segments of 153 characters. | |
29 | // So it could hypothetically fit in segments of 153 characters. | |
30 | // But it can't because the extended character can't be cut in the | |
31 | // middle. | |
32 | // We need to add 1 to message length to generate an additional segment | |
33 | // TODO: improve this | |
34 |
6
1. count : Replaced integer modulus with multiplication → NO_COVERAGE 2. count : negated conditional → NO_COVERAGE 3. count : negated conditional → NO_COVERAGE 4. count : Replaced integer modulus with multiplication → KILLED 5. count : negated conditional → KILLED 6. count : negated conditional → KILLED |
if (originalLength == extendedChars && extendedChars % MAXIMUM_SPLIT_SEGMENT_LENGTH == 0) { |
35 |
6
1. count : Replaced integer addition with subtraction → NO_COVERAGE 2. count : Replaced integer addition with subtraction → NO_COVERAGE 3. count : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::count → NO_COVERAGE 4. count : Replaced integer addition with subtraction → KILLED 5. count : Replaced integer addition with subtraction → KILLED 6. count : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::count → KILLED |
return originalLength + extendedChars + 1; |
36 | } | |
37 |
4
1. count : Replaced integer addition with subtraction → NO_COVERAGE 2. count : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::count → NO_COVERAGE 3. count : Replaced integer addition with subtraction → KILLED 4. count : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::count → KILLED |
return originalLength + extendedChars; |
38 | } | |
39 | ||
40 | private static int countExtendedChars(String str) { | |
41 | int found = 0; | |
42 | int len = str.length(); | |
43 |
6
1. countExtendedChars : changed conditional boundary → NO_COVERAGE 2. countExtendedChars : Changed increment from 1 to -1 → NO_COVERAGE 3. countExtendedChars : negated conditional → NO_COVERAGE 4. countExtendedChars : changed conditional boundary → KILLED 5. countExtendedChars : Changed increment from 1 to -1 → KILLED 6. countExtendedChars : negated conditional → KILLED |
for (int i = 0; i < len; i++) { |
44 | int search = 0; | |
45 | char c = str.charAt(i); | |
46 |
6
1. countExtendedChars : changed conditional boundary → NO_COVERAGE 2. countExtendedChars : Changed increment from 1 to -1 → NO_COVERAGE 3. countExtendedChars : negated conditional → NO_COVERAGE 4. countExtendedChars : changed conditional boundary → KILLED 5. countExtendedChars : Changed increment from 1 to -1 → KILLED 6. countExtendedChars : negated conditional → KILLED |
for (; search < EXT_CHARS.length; search++) { |
47 |
2
1. countExtendedChars : negated conditional → NO_COVERAGE 2. countExtendedChars : negated conditional → KILLED |
if (c == EXT_CHARS[search]) { |
48 |
2
1. countExtendedChars : Changed increment from 1 to -1 → NO_COVERAGE 2. countExtendedChars : Changed increment from 1 to -1 → KILLED |
found++; |
49 | break; | |
50 | } | |
51 | } | |
52 | } | |
53 |
2
1. countExtendedChars : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::countExtendedChars → NO_COVERAGE 2. countExtendedChars : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::countExtendedChars → KILLED |
return found; |
54 | } | |
55 | ||
56 | } | |
Mutations | ||
34 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
35 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
37 |
1.1 2.2 3.3 4.4 |
|
43 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
46 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
47 |
1.1 2.2 |
|
48 |
1.1 2.2 |
|
53 |
1.1 2.2 |