File: rename_cpp.sh

package info (click to toggle)
qgis 3.40.15%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,185,444 kB
  • sloc: cpp: 1,616,454; python: 372,967; xml: 23,474; sh: 3,761; perl: 3,664; ansic: 2,829; sql: 2,137; yacc: 1,068; lex: 577; javascript: 540; lisp: 411; makefile: 155
file content (37 lines) | stat: -rwxr-xr-x 1,028 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash

# This scripts renames the name of a class as well as its header and cpp file
# (assuming they are the lowercase version of the class name).
#
# Usage: ./scripts/rename_cpp.sh src/core QgsMyClassName QgsMyNewClassName

set -e

# GNU prefix command for bsd/mac os support (gsed, gsplit)
GP=
if [[ "$OSTYPE" == *bsd* ]] || [[ "$OSTYPE" =~ darwin* ]]; then
  GP=g
fi

FILEPATH=$1
OLD_CLASSNAME=$2
NEW_CLASSNAME=$3

OLD_CLASSUPPER="${OLD_CLASSNAME^^}"
OLD_CLASSLOWER="${OLD_CLASSNAME,,}"
NEW_CLASSUPPER="${NEW_CLASSNAME^^}"
NEW_CLASSLOWER="${NEW_CLASSNAME,,}"


FILES=$(git grep $OLD_CLASSLOWER -- src python | cut -d: -f1)
for f in ${FILES}; do
echo "replacing in $f..."
  ${GP}sed -i "s/\b${OLD_CLASSNAME}\b/${NEW_CLASSNAME}/g" $f
  ${GP}sed -i "s/\b${OLD_CLASSUPPER}\b/${NEW_CLASSUPPER}/g" $f
  ${GP}sed -i "s/\b${OLD_CLASSLOWER}\b/${NEW_CLASSLOWER}/g" $f
done

set +e

mv ${FILEPATH}/${OLD_CLASSLOWER}.h ${FILEPATH}/${NEW_CLASSLOWER}.h
mv ${FILEPATH}/${OLD_CLASSLOWER}.cpp ${FILEPATH}/${NEW_CLASSLOWER}.cpp