001    package org.rakeshv.utils;
002    
003    /**
004            *       <p>Convert ISO character entities into their equivalent
005            *       7-bit ASCII characters, or 
006            *       L<sup><small>A</small></sup>T<sub><small>E</small></sub>X
007            *       equivalents.</p>
008            *
009            *       <p>Looks for the characters that are above 127, and tries to match
010            *       them against the characters specified in the HTML specification
011            *       (http://www.w3.org/TR/html4/sgml/entities.html).</p>
012            *
013            *       <p>Uses {@link org.rakeshv.tex.ISOToASCII ISOToASCII} and
014            *       {@link org.rakeshv.tex.ISOToTeX ISOToTeX} <code>HashMaps</code>
015            *       to perform the lookups.</p>
016            */
017    public class LaTeXAccents
018    {
019            /**
020                    *       The <code>String</code> object that holds the modified contents.
021                    */
022            private String content = "";
023    
024            /**
025                    *       <p>Default constructor.  Cannot be invoked.</p>
026                    */
027            private LaTeXAccents()
028            {
029                    super();
030            }
031    
032            /**
033                    * <p>Modifies all accentuated characters in the specified
034                    *       <code>String</code>
035                    *
036                    *       @param inString - The input <code>String</code> to process.
037                    */
038            public LaTeXAccents( String inString )
039            {
040                    content = modifyContent( inString );
041            }
042    
043            /**
044                    *       The method in which the conversion of the characters is done.
045                    *
046                    *       @param inString - The input <code>String</code> that
047                    *               is to be processed.
048                    *       @return String - The modified <code>String</code> object.
049                    */
050            private String modifyContent( String inString )
051            {
052                    StringBuilder content = new StringBuilder( inString.length() );
053    
054                    for ( int i = 0; i < inString.length(); ++i )
055                    {
056                            char currentChar = inString.charAt( i );
057                            switch ( currentChar )
058                            {
059            case 160:
060                                    {
061                                            content.append( "{\\~}" );
062                                            break;
063                                    }
064            case 161:
065                                    {
066                                            content.append( "{!`}" );
067                                            break;
068                                    }
069            case 163:
070                                    {
071                                            content.append( "{\\pounds}" );
072                                            break;
073                                    }
074            case 167:
075                                    {
076                                            content.append( "{\\S}" );
077                                            break;
078                                    }
079            case 168:
080                                    {
081                                            content.append( "\\\"{ }" );
082                                            break;
083                                    }
084            case 169:
085                                    {
086                                            content.append( "{\\copyright}" );
087                                            break;
088                                    }
089            case 171:
090                                    {
091                                            content.append( "{\\ensuremath{\\ll}}" );
092                                            break;
093                                    }
094            case 172:
095                                    {
096                                            content.append( "{\\ensuremath{\\neg}}" );
097                                            break;
098                                    }
099            case 173:
100                                    {
101                                            content.append( "{\\textendash}" );
102                                            break;
103                                    }
104            case 174:
105                                    {
106                                            content.append( "$^{\\ooalign{\\hfil\\raise.07ex\\hbox{\\rm\\tiny R}\\hfil\\crcr{\\scriptsize\\mathhexbox20D}}}$" );
107                                            break;
108                                    }
109            case 175:
110                                    {
111                                            content.append( "\\ensuremath{^-}" );
112                                            break;
113                                    }
114            case 176:
115                                    {
116                                            content.append( "{\\ensuremath{^\\circ}}" );
117                                            break;
118                                    }
119            case 177:
120                                    {
121                                            content.append( "{\\ensuremath{\\pm}}" );
122                                            break;
123                                    }
124            case 178:
125                                    {
126                                            content.append( "{\\ensuremath{^2}}" );
127                                            break;
128                                    }
129            case 179:
130                                    {
131                                            content.append( "{\\ensuremath{^3}}" );
132                                            break;
133                                    }
134            case 180:
135                                    {
136                                            content.append( "{\\ensuremath{^\\prime}}" );
137                                            break;
138                                    }
139            case 181:
140                                    {
141                                            content.append( "{\\ensuremath{\\mu}}" );
142                                            break;
143                                    }
144            case 182:
145                                    {
146                                            content.append( "{\\P}" );
147                                            break;
148                                    }
149            case 183:
150                                    {
151                                            content.append( "{\\ensuremath{\\cdot}}" );
152                                            break;
153                                    }
154            case 184:
155                                    {
156                                            content.append( "{\\c{ }}" );
157                                            break;
158                                    }
159            case 185:
160                                    {
161                                            content.append( "{\\ensuremath{^1}}" );
162                                            break;
163                                    }
164            case 187:
165                                    {
166                                            content.append( "{\\ensuremath{\\gg}}" );
167                                            break;
168                                    }
169            case 188:
170                                    {
171                                            content.append( "{\\ensuremath{\\frac{1}{4}}}" );
172                                            break;
173                                    }
174            case 189:
175                                    {
176                                            content.append( "{\\ensuremath{\\frac{1}{2}}}" );
177                                            break;
178                                    }
179            case 190:
180                                    {
181                                            content.append( "{\\ensuremath{\\frac{3}{4}}}" );
182                                            break;
183                                    }
184            case 191:
185                                    {
186                                            content.append( "{?`}" );
187                                            break;
188                                    }
189            case 192:
190                                    {
191                                            content.append( "\\`{A}" );
192                                            break;
193                                    }
194            case 193:
195                                    {
196                                            content.append( "\\'{A}" );
197                                            break;
198                                    }
199            case 194:
200                                    {
201                                            content.append( "\\^{A}" );
202                                            break;
203                                    }
204            case 195:
205                                    {
206                                            content.append( "\\~{A}" );
207                                            break;
208                                    }
209            case 196:
210                                    {
211                                            content.append( "\\\"{A}" );
212                                            break;
213                                    }
214            case 197:
215                                    {
216                                            content.append( "\\r{A}" );
217                                            break;
218                                    }
219            case 198:
220                                    {
221                                            content.append( "{\\AE}" );
222                                            break;
223                                    }
224            case 199:
225                                    {
226                                            content.append( "\\c{C}" );
227                                            break;
228                                    }
229            case 200:
230                                    {
231                                            content.append( "\\`{E}" );
232                                            break;
233                                    }
234            case 201:
235                                    {
236                                            content.append( "\\'{E}" );
237                                            break;
238                                    }
239            case 202:
240                                    {
241                                            content.append( "\\^{E}" );
242                                            break;
243                                    }
244            case 203:
245                                    {
246                                            content.append( "\\\"{E}" );
247                                            break;
248                                    }
249            case 204:
250                                    {
251                                            content.append( "\\`{I}" );
252                                            break;
253                                    }
254            case 205:
255                                    {
256                                            content.append( "\\'{I}" );
257                                            break;
258                                    }
259            case 206:
260                                    {
261                                            content.append( "\\^{I}" );
262                                            break;
263                                    }
264            case 207:
265                                    {
266                                            content.append( "\\\"{I}" );
267                                            break;
268                                    }
269            case 209:
270                                    {
271                                            content.append( "\\~{N}" );
272                                            break;
273                                    }
274            case 210:
275                                    {
276                                            content.append( "\\`{O}" );
277                                            break;
278                                    }
279            case 211:
280                                    {
281                                            content.append( "\\'{O}" );
282                                            break;
283                                    }
284            case 212:
285                                    {
286                                            content.append( "\\^{O}" );
287                                            break;
288                                    }
289            case 213:
290                                    {
291                                            content.append( "\\~{O}" );
292                                            break;
293                                    }
294            case 214:
295                                    {
296                                            content.append( "\\\"{O}" );
297                                            break;
298                                    }
299            case 215:
300                                    {
301                                            content.append( "{\\ensuremath{\\times}}" );
302                                            break;
303                                    }
304            case 216:
305                                    {
306                                            content.append( "{\\O}" );
307                                            break;
308                                    }
309            case 217:
310                                    {
311                                            content.append( "\\`{U}" );
312                                            break;
313                                    }
314            case 218:
315                                    {
316                                            content.append( "\\'{U}" );
317                                            break;
318                                    }
319            case 219:
320                                    {
321                                            content.append( "\\^{U}" );
322                                            break;
323                                    }
324            case 220:
325                                    {
326                                            content.append( "\\\"{U}" );
327                                            break;
328                                    }
329            case 221:
330                                    {
331                                            content.append( "\\'{Y}" );
332                                            break;
333                                    }
334            case 223:
335                                    {
336                                            content.append( "{\\ss}" );
337                                            break;
338                                    }
339            case 224:
340                                    {
341                                            content.append( "\\`{a}" );
342                                            break;
343                                    }
344            case 225:
345                                    {
346                                            content.append( "\\'{a}" );
347                                            break;
348                                    }
349            case 226:
350                                    {
351                                            content.append( "\\^{a}" );
352                                            break;
353                                    }
354            case 227:
355                                    {
356                                            content.append( "\\~{a}" );
357                                            break;
358                                    }
359            case 228:
360                                    {
361                                            content.append( "\\\"{a}" );
362                                            break;
363                                    }
364            case 229:
365                                    {
366                                            content.append( "\\r{a}" );
367                                            break;
368                                    }
369            case 230:
370                                    {
371                                            content.append( "{\\ae}" );
372                                            break;
373                                    }
374            case 231:
375                                    {
376                                            content.append( "\\c{c}" );
377                                            break;
378                                    }
379            case 232:
380                                    {
381                                            content.append( "\\`{e}" );
382                                            break;
383                                    }
384            case 233:
385                                    {
386                                            content.append( "\\'{e}" );
387                                            break;
388                                    }
389            case 234:
390                                    {
391                                            content.append( "\\^{e}" );
392                                            break;
393                                    }
394            case 235:
395                                    {
396                                            content.append( "\\\"{e}" );
397                                            break;
398                                    }
399            case 236:
400                                    {
401                                            content.append( "\\`{i}" );
402                                            break;
403                                    }
404            case 237:
405                                    {
406                                            content.append( "\\'{i}" );
407                                            break;
408                                    }
409            case 238:
410                                    {
411                                            content.append( "\\^{i}" );
412                                            break;
413                                    }
414            case 239:
415                                    {
416                                            content.append( "\\\"{i}" );
417                                            break;
418                                    }
419            case 241:
420                                    {
421                                            content.append( "\\~{n}" );
422                                            break;
423                                    }
424            case 242:
425                                    {
426                                            content.append( "\\`{o}" );
427                                            break;
428                                    }
429            case 243:
430                                    {
431                                            content.append( "\\'{o}" );
432                                            break;
433                                    }
434            case 244:
435                                    {
436                                            content.append( "\\^{o}" );
437                                            break;
438                                    }
439            case 245:
440                                    {
441                                            content.append( "\\~{o}" );
442                                            break;
443                                    }
444            case 246:
445                                    {
446                                            content.append( "\\\"{o}" );
447                                            break;
448                                    }
449            case 247:
450                                    {
451                                            content.append( "{\\ensuremath{\\div}}" );
452                                            break;
453                                    }
454            case 248:
455                                    {
456                                            content.append( "{\\o}" );
457                                            break;
458                                    }
459            case 249:
460                                    {
461                                            content.append( "\\`{u}" );
462                                            break;
463                                    }
464            case 250:
465                                    {
466                                            content.append( "\\'{u}" );
467                                            break;
468                                    }
469            case 251:
470                                    {
471                                            content.append( "\\^{u}" );
472                                            break;
473                                    }
474            case 252:
475                                    {
476                                            content.append( "\\\"{u}" );
477                                            break;
478                                    }
479            case 253:
480                                    {
481                                            content.append( "\\'{y}" );
482                                            break;
483                                    }
484            case 255:
485                                    {
486                                            content.append( "\\\"{y}" );
487                                            break;
488                                    }
489                                    default:
490                                    {
491                                            content.append( currentChar );
492                                            break;
493                                    }
494                            }
495                    }
496    
497        return content.toString();
498            }
499            
500            /**
501             * Returns {@link #content}.
502             *
503             * @return String - The value/reference of/to content.
504             */
505            public final String getContent()
506            {
507              return content;
508            }
509    }