A Simple Shell Script to Check the Trap of Case-Insensitive String

In the post of "The Trap of Case-Insensitive String", it is talked about the locale sensitive of String.toUpperCase() or String.toLowerCase(). I wrote a very simple KSH script to check the potential problems in Java source code. The script may be useful to facilitate the checking of the trap.

#!/bin/ksh

set -A KEYWORDS
KEYWORDS[0]="toLowerCase\(\)|toUpperCase\(\)"
typeset -i keywords_number=1

# KEYWORDS[0]="toLowerCase\(\).hashCode\(\)"
# KEYWORDS[1]="toUpperCase\(\).hashCode\(\)"
# KEYWORDS[2]="toLowerCase\(\).equals\("
# KEYWORDS[3]="toUpperCase\(\).equals\("
# typeset -i keywords_number=4

EXCLUDE_LINES="\/\/| \* "   # inaccurate filter

typeset -i keywords_i=0
while [ ${keywords_i} -lt ${keywords_number} ]; do
    echo
    echo Running "Checking operatoin ${KEYWORDS[${keywords_i}]} ..."

    find ./ -name "*.java" |xargs egrep "${KEYWORDS[${keywords_i}]}" \
        |egrep -v "${EXCLUDE_LINES}"

    echo "    ... DONE with the checking of ${KEYWORDS[${keywords_i}]}"
    echo

    ((keywords_i=keywords_i+1))
done


Please check the output to make sure there is no potential issues with String.toUpperCase() or String.toLowerCase().

Enjoy it!

Popular posts from this blog

Understanding of OCSP Stapling

TLS Server Name Indication Extension and Unrecognized_name

JEP 115: AES-GCM CipherSuites in JDK 8