Skip to content

Commit b015a1c

Browse files
committed
Merge pull request #84 from zbeekman/feat-UTF-8-support-issue-35
Feat utf 8 support issue 35
2 parents 8b53d37 + 0d0ce43 commit b015a1c

16 files changed

+2565
-585
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ builds/
66
*.obj
77
*.manifest
88
.sconsign.*
9+
files/*.json
10+
src/tests/jf_test_example[12].f90
911
documentation/
1012
visual_studio_2010/*.suo
1113
visual_studio_2010/*.u2d

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ env:
1313
matrix:
1414
# CMake build with unit tests, no documentation, no coverage analysis
1515
# Allow to fail for now until tests are fixed
16-
- BUILD_SCRIPT="mkdir cmake-build && cd cmake-build && cmake -DSKIP_DOC_GEN:BOOL=TRUE .. && make -j 4 && make test"
16+
- BUILD_SCRIPT="mkdir cmake-build && cd cmake-build && cmake -DSKIP_DOC_GEN:BOOL=TRUE -DENABLE_UNICODE:BOOL=TRUE .. && make -j 4 && make test"
1717
SPECIFIC_DEPENDS="cmake nodejs"
1818
JLINT="yes"
1919
DOCS="no"
2020
FoBiS="no"
2121

2222
# build with build.sh, make documentation, run unit tests and perform coverage analysis
23-
- BUILD_SCRIPT="./build.sh"
23+
- BUILD_SCRIPT="./build.sh --coverage --enable-unicode"
2424
SPECIFIC_DEPENDS="binutils"
2525
JLINT="no"
2626
DOCS="yes"
@@ -59,7 +59,7 @@ script:
5959

6060
after_success:
6161
- cd $TRAVIS_BUILD_DIR
62-
- if [[ $CODE_COVERAGE == [yY]* ]]; then gcov -o lib/ src/json_module.f90 && coveralls -n -b . ; fi
62+
- if [[ $CODE_COVERAGE == [yY]* ]]; then gcov -o lib/ src/json_module.F90 && coveralls -n -b . ; fi
6363
- git config --global user.name "TRAVIS-CI-for-$(git --no-pager show -s --format='%cn' $TRAVIS_COMMIT)"
6464
- git config --global user.email "$(git --no-pager show -s --format='%ce' $TRAVIS_COMMIT)"
6565
- ./deploy.sh #handles updating documentation for master branch as well as tags

CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ set ( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
4141
#-------------------------------------
4242
# Collect source files for the library
4343
#-------------------------------------
44-
set ( JF_LIB_SRCS src/json_module.f90 )
44+
set ( JF_LIB_SRCS src/json_module.F90 )
4545
file ( GLOB JF_TEST_SRCS "src/tests/jf_test_*.f90" )
46+
set ( JF_TEST_UCS4_SUPPORT_SRC "${CMAKE_SOURCE_DIR}/src/tests/introspection/test_iso_10646_support.f90")
4647

4748
#-----------------------------------------
4849
# Collect all the mod files into their own
@@ -83,6 +84,22 @@ else ()
8384
"${ABS_LIB_INSTALL_DIR}" )
8485
endif ()
8586

87+
#---------------------------------------------
88+
# See if our compiler supports ISO 10646/UCS4
89+
#---------------------------------------------
90+
set ( ENABLE_UNICODE FLASE CACHE BOOL
91+
"Enable unicode/UCS4 support" )
92+
if ( ENABLE_UNICODE )
93+
try_run( UCS4_TEST_RUNS UCS4_TEST_COMPILES
94+
${CMAKE_BINARY_DIR}/bin ${JF_TEST_UCS4_SUPPORT_SRC} )
95+
if (UCS4_TEST_RUNS EQUAL 0)
96+
add_definitions (-DUSE_UCS4)
97+
else ()
98+
message ( WARNING
99+
"Unicode support requested but ${CMAKE_Fortran_COMPILER_ID} Fortran compiler does not support 'ISO_10646' characters!" )
100+
endif ()
101+
endif ()
102+
86103
#---------------------------------------------
87104
# Build a shared and static library by default
88105
#---------------------------------------------

SConstruct

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import sys
1717
env = Environment()
1818

1919
if env['FORTRAN'] == 'gfortran':
20-
env = Environment(F90FLAGS = '-O2 -fbacktrace -g -Wall -Wextra -Wno-maybe-uninitialized -pedantic -std=f2008 -J',)
20+
env = Environment(F90FLAGS = '-O2 -fbacktrace -g -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-function -pedantic -std=f2008 -J',)
2121
elif env['FORTRAN'] == 'ifort':
2222
env = Environment(F90FLAGS = '-O2 -warn -stand f08 -diag-disable 7601 -traceback -module lib',)
2323

24-
src = join('src','json_module.f90')
24+
src = join('src','json_module.F90')
2525
ar = join('lib','libjsonfortran'+env['LIBSUFFIX'])
2626
sl = join('lib','libjsonfortran'+env['SHLIBSUFFIX'])
2727
mod = join('lib','json_module.mod') ## FORTRANMODSUFFIX
@@ -34,8 +34,7 @@ obj = []
3434
exe = []
3535
here = os.getcwd()
3636
os.chdir(join('src', 'tests'))
37-
for f in sorted(glob.glob("*")):
38-
if not f.endswith('f90'): continue
37+
for f in sorted(glob.glob("*.[fF]90")):
3938
tests.append(join('src', 'tests', f))
4039
e = f[:-4]
4140
obj.append(join('src','tests',e+env['OBJSUFFIX']))

build.sh

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@ PROJECTNAME='jsonfortran' # project name for robodoc (example: jsonfortran
2525
DOCDIR='./documentation/' # build directory for documentation
2626
SRCDIR='./src/' # library source directory
2727
TESTDIR='./src/tests/' # unit test source directory
28+
INTROSPECDIR='./src/tests/introspection/' # pre compile configuration tests directory
29+
UCS4TESTCODE='test_iso_10646_support.f90'
2830
BINDIR='./bin/' # build directory for unit tests
2931
LIBDIR='./lib/' # build directory for library
30-
MODCODE='json_module.f90' # json module file name
32+
MODCODE='json_module.F90' # json module file name
3133
LIBOUT='libjsonfortran.a' # name of json library
3234

3335

3436
# The following warning might be triggered by ifort unless explicitly silenced:
3537
# warning #7601: F2008 standard does not allow an internal procedure to be an actual argument procedure name. (R1214.4).
3638
# In the context of F2008 this is an erroneous warning.
3739
# See https://prd1idz.cps.intel.com/en-us/forums/topic/486629
38-
INTELCOMPILERFLAGS='-c -O2 -warn -stand f08 -diag-disable 7601 -traceback'
40+
INTELCOMPILERFLAGS='-c -O2 -warn -stand f08 -diag-disable 7601 -diag-disable 4013 -traceback'
3941
#INTELCOMPILERFLAGS='-c -O2 -warn -traceback -stand f08 -assume protect_parens -assume buffered_io -check all'
4042

41-
GNUCOMPILERFLAGS='-c -O2 -fbacktrace -Wall -Wextra -Wno-maybe-uninitialized -pedantic -std=f2008'
43+
GNUCOMPILERFLAGS='-c -O2 -fbacktrace -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-function -pedantic -std=f2008'
4244

4345
FCOMPILER='gnu' #Set default compiler to gfortran
4446

@@ -55,7 +57,7 @@ print_usage () {
5557
echo -e "\n\nUsage:\n"
5658
echo -e "${script_name} [--compiler {intel|gnu|<other>}] [--cflags '<custom compiler flags here>']\n\
5759
[--coverage [{yes|no}]] [--profile [{yes|no}]] [--skip-tests [{yes|no}]]\n\
58-
[--skip-documentation [{yes|no}]] [--help]"
60+
[--skip-documentation [{yes|no}]] [--enable-unicode [{yes|no}]] [--help]"
5961
echo ""
6062
echo -e "Any flags that take an optional yes or no argument will default to 'yes' when no\n\
6163
argument is passed. Additionally, A custom compiler may be passed to the 'compiler'\n\
@@ -94,6 +96,22 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
9496
# no good way to check that the user didn't do something questionable
9597
shift
9698
;;
99+
--enable-unicode)
100+
case $2 in
101+
yes|Yes|YES)
102+
TRY_UNICODE="yes"
103+
shift
104+
;;
105+
no|No|NO)
106+
TRY_UNICODE="no"
107+
shift
108+
;;
109+
*)
110+
TRY_UNICODE="yes"
111+
# don't shift; $2 is next arg
112+
;;
113+
esac
114+
;;
97115
--coverage) # enable coverage
98116
case $2 in
99117
yes|Yes|YES)
@@ -185,17 +203,26 @@ if [[ $CODE_PROFILE == [yY]* ]]; then
185203
fi
186204

187205
if [[ $FCOMPILER == custom ]]; then
206+
echo "Trying to compile with custom compiler, $FC"
188207
CUSTOM="-fc $FC"
189208
fi
190209

210+
if [[ $TRY_UNICODE == [yY]* ]]; then
211+
echo "Trying to compile library with Unicode/UCS4 support"
212+
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS}" -dbld "${BINDIR}" -s "${INTROSPECDIR}" -dmod ./ -dobj ./ -t ${UCS4TESTCODE} -o ${UCS4TESTCODE%.f90} -colors
213+
if "${BINDIR}/${UCS4TESTCODE%.f90}"; then
214+
DEFINES="-DUSE_UCS4 -Wunused-function"
215+
fi
216+
fi
217+
191218
#build the stand-alone library:
192219
echo ""
193220
echo "Building library..."
194221

195222
# work around for FoBiS.py PR #45
196223
[ -d "$LIBDIR" ] || mkdir "$LIBDIR"
197224

198-
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS}" ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
225+
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
199226

200227
#build the unit tests (uses the above library):
201228
if [[ $JF_SKIP_TESTS != [yY]* ]]; then
@@ -205,10 +232,10 @@ if [[ $JF_SKIP_TESTS != [yY]* ]]; then
205232
# FoBiS.py PR #45 work around
206233
[ -d "$BINDIR" ] || mkdir "$BINDIR"
207234

208-
for TEST in "${TESTDIR%/}"/jf_test_*.f90; do
235+
for TEST in "${TESTDIR%/}"/jf_test_*.[fF]90; do
209236
THIS_TEST=${TEST##*/}
210-
echo "Build ${THIS_TEST%.f90}"
211-
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS}" ${COVERAGE} ${PROFILING} -dbld ${BINDIR} -s ${TESTDIR} -i ${LIBDIR} -libs ${LIBDIR}/${LIBOUT} -dmod ./ -dobj ./ -t ${THIS_TEST} -o ${THIS_TEST%.f90} -colors
237+
echo "Build ${THIS_TEST%.[fF]90}"
238+
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld ${BINDIR} -s ${TESTDIR} -i ${LIBDIR} -libs ${LIBDIR}/${LIBOUT} -dmod ./ -dobj ./ -t ${THIS_TEST} -o ${THIS_TEST%.[fF]90} -colors
212239
done
213240
else
214241
echo "Skip building the unit tests since \$JF_SKIP_TESTS has been set to 'true'."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../inputs/hello-world-ascii.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../inputs/hello-world-ucs4.json

files/inputs/hello-world-ascii.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"hello world": {
3+
"Chinese": "\u4f60\u597d\u4e16\u754c",
4+
"Dutch": "Hello wereld",
5+
"English": "Hello world",
6+
"French": "Bonjour monde",
7+
"German": "Hallo Welt",
8+
"Greek": "\u03b3\u03b5\u03b9\u03ac \u03c3\u03bf\u03c5 \u03ba\u03cc\u03c3\u03bc\u03bf\u03c2",
9+
"Italian": "Ciao mondo",
10+
"Japanese": "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c",
11+
"Korean": "\uc5ec\ubcf4\uc138\uc694 \uc138\uacc4",
12+
"Portuguese": "Ol\u00e1 mundo",
13+
"Russian": "\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u043b\u0442\u0435 \u043c\u0438\u0440",
14+
"Spanish": "Hola mundo",
15+
"Amharic": "\u1235\u120b\u121d \u12a0\u1208\u121d",
16+
"Hebrew": "\u05e9\u05dc\u05d5\u05dd \u05e2\u05d5\u05dc\u05dd",
17+
"Hindi": "\u0939\u0948\u0932\u094b \u0935\u0930\u094d\u0932\u094d\u0921",
18+
"Arabic": "\u0645\u0631\u062d\u0628\u0627 \u0628\u0627\u0644\u0639\u0627\u0644\u0645",
19+
"Urdu": "\u06c1\u06cc\u0644\u0648 \u062f\u0646\u06cc\u0627",
20+
"Thai": "\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35\u0e0a\u0e32\u0e27\u0e42\u0e25\u0e01"
21+
},
22+
"UCS4 support?": "\u2713"
23+
}

files/inputs/hello-world-ucs4.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"hello world": {
3+
"Chinese": "你好世界",
4+
"Dutch": "Hello wereld",
5+
"English": "Hello world",
6+
"French": "Bonjour monde",
7+
"German": "Hallo Welt",
8+
"Greek": "γειά σου κόσμος",
9+
"Italian": "Ciao mondo",
10+
"Japanese": "こんにちは世界",
11+
"Korean": "여보세요 세계",
12+
"Portuguese": "Olá mundo",
13+
"Russian": "Здравствулте мир",
14+
"Spanish": "Hola mundo",
15+
"Amharic": "ስላም አለም",
16+
"Hebrew": "שלום עולם",
17+
"Hindi": "हैलो वर्ल्ड",
18+
"Arabic": "مرحبا بالعالم",
19+
"Urdu": "ہیلو دنیا",
20+
"Thai": "สวัสดีชาวโลก"
21+
},
22+
"UCS4 support?": ""
23+
}

0 commit comments

Comments
 (0)