Default constructor. @param aString The description string.
(final String aString)
| 62 | * @param aString The description string. |
| 63 | */ |
| 64 | public Description(final String aString) |
| 65 | { |
| 66 | int currentInd = 0; |
| 67 | int percentInd; |
| 68 | while ((percentInd = aString.indexOf('%', currentInd)) != -1) |
| 69 | { |
| 70 | final String preText = aString.substring(currentInd, percentInd); |
| 71 | if (!preText.isEmpty()) |
| 72 | { |
| 73 | theComponents.add(preText); |
| 74 | } |
| 75 | if (percentInd == aString.length() - 1) |
| 76 | { |
| 77 | theComponents.add("%"); //$NON-NLS-1$ |
| 78 | return; |
| 79 | } |
| 80 | if (aString.charAt(percentInd + 1) == '{') |
| 81 | { |
| 82 | // This is a bracketed placeholder. The replacement parameter |
| 83 | // is contained within the {} |
| 84 | currentInd = aString.indexOf('}', percentInd + 1) + 1; |
| 85 | final String replacement = aString.substring(percentInd + 1, currentInd); |
| 86 | // For the time being we will only support numerics here. |
| 87 | try |
| 88 | { |
| 89 | Integer.parseInt(replacement); |
| 90 | } |
| 91 | catch (NumberFormatException nfe) |
| 92 | { |
| 93 | Logging.errorPrintLocalised( |
| 94 | "Errors.Description.InvalidVariableReplacement", replacement); //$NON-NLS-1$ |
| 95 | } |
| 96 | theComponents.add(VAR_MARKER + replacement); |
| 97 | } |
| 98 | else if (aString.charAt(percentInd + 1) == '%') |
| 99 | { |
| 100 | // This is an escape sequence so we can actually print a % |
| 101 | currentInd = percentInd + 2; |
| 102 | theComponents.add("%"); //$NON-NLS-1$ |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | // In this case we have an unbracketed placeholder. We will |
| 107 | // walk the string until such time as we no longer have a number |
| 108 | currentInd = percentInd + 1; |
| 109 | while (currentInd < aString.length()) |
| 110 | { |
| 111 | final char val = aString.charAt(currentInd); |
| 112 | try |
| 113 | { |
| 114 | Integer.parseInt(String.valueOf(val)); |
| 115 | currentInd++; |
| 116 | } |
| 117 | catch (NumberFormatException nfe) |
| 118 | { |
| 119 | break; |
| 120 | } |
| 121 | } |
nothing calls this directly
no test coverage detected