Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Apr 5, 2024
1 parent 7ff90a3 commit 3210fa6
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 149 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ TARGET = $(DISTDIR)/libdmpack.a
SHARED = $(DISTDIR)/libdmpack.so

# Debug and release options.
DEBUG = -g -O0 -Wall -fcheck=all -fmax-errors=1
DEBUG = -g -O0 -Wall -Wpedantic -fcheck=all -fmax-errors=1
RELEASE = -mtune=native -O2

# Common build options.
Expand Down Expand Up @@ -289,6 +289,7 @@ SRC = $(SRCDIR)/dm_ansi.f90 \
$(SRCDIR)/dm_util.f90 \
$(SRCDIR)/dm_uuid.f90 \
$(SRCDIR)/dm_version.f90 \
$(SRCDIR)/dm_z.f90 \
$(SRCDIR)/dm_zlib.f90 \
$(SRCDIR)/dm_zstd.f90 \
$(SRCDIR)/dmpack.f90
Expand Down Expand Up @@ -375,6 +376,7 @@ OBJ = dm_ansi.o \
dm_util.o \
dm_uuid.o \
dm_version.o \
dm_z.o \
dm_zlib.o \
dm_zstd.o \
dmpack.o
Expand Down Expand Up @@ -549,6 +551,7 @@ $(OBJ): $(SRC)
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_db.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_zlib.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_zstd.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_z.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_person.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_mail.f90
$(FC) $(FFLAGS) $(LDFLAGS) -c src/dm_http.f90
Expand Down
76 changes: 38 additions & 38 deletions src/dm_ascii.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module dm_ascii

public :: dm_ascii_escape
public :: dm_ascii_is_alpha
public :: dm_ascii_is_alpha_num
public :: dm_ascii_is_alpha_numeric
public :: dm_ascii_is_blank
public :: dm_ascii_is_control
public :: dm_ascii_is_digit
Expand Down Expand Up @@ -97,96 +97,96 @@ pure function dm_ascii_escape(str) result(res)
end do
end function dm_ascii_escape

pure elemental logical function dm_ascii_is_alpha(a) result(is_alpha)
pure elemental logical function dm_ascii_is_alpha(a) result(is)
!! Returns whether character is alpha letter.
character, intent(in) :: a !! Character to check.

is_alpha = (a >= 'A' .and. a <= 'Z') .or. (a >= 'a' .and. a <= 'z')
is = ((a >= 'A' .and. a <= 'Z') .or. (a >= 'a' .and. a <= 'z'))
end function dm_ascii_is_alpha

pure elemental logical function dm_ascii_is_alpha_num(a) result(is_alpha_num)
pure elemental logical function dm_ascii_is_alpha_numeric(a) result(is)
!! Returns whether character is alpha-numeric.
character, intent(in) :: a !! Character to check.

is_alpha_num = (a >= '0' .and. a <= '9') .or. &
(a >= 'A' .and. a <= 'Z') .or. &
(a >= 'a' .and. a <= 'z')
end function dm_ascii_is_alpha_num
is = ((a >= '0' .and. a <= '9') .or. &
(a >= 'A' .and. a <= 'Z') .or. &
(a >= 'a' .and. a <= 'z'))
end function dm_ascii_is_alpha_numeric

pure elemental logical function dm_ascii_is_blank(a) result(is_blank)
pure elemental logical function dm_ascii_is_blank(a) result(is)
!! Returns whether character is space or tabular.
character, intent(in) :: a !! Character to check.
integer :: i
integer :: ia

i = iachar(a)
is_blank = (a == ' ') .or. (i == int(z'09'))
ia = iachar(a)
is = ((a == ' ') .or. (ia == int(z'09')))
end function dm_ascii_is_blank

pure elemental logical function dm_ascii_is_control(a) result(is_control)
pure elemental logical function dm_ascii_is_control(a) result(is)
!! Returns whether character is control character.
character, intent(in) :: a !! Character to check.
integer :: i
integer :: ia

i = iachar(a)
is_control = (i < int(z'20')) .or. (i == int(z'7F'))
ia = iachar(a)
is = ((ia < int(z'20')) .or. (ia == int(z'7F')))
end function dm_ascii_is_control

pure elemental logical function dm_ascii_is_digit(a) result(is_digit)
pure elemental logical function dm_ascii_is_digit(a) result(is)
!! Returns whether character is digit.
character, intent(in) :: a !! Character to check.

is_digit = (a >= '0') .and. (a <= '9')
is = ((a >= '0') .and. (a <= '9'))
end function dm_ascii_is_digit

pure elemental logical function dm_ascii_is_hex_digit(a) result(is_hex)
pure elemental logical function dm_ascii_is_hex_digit(a) result(is)
!! Returns whether character is hex digit.
character, intent(in) :: a !! Character to check.

is_hex = (a >= '0' .and. a <= '9') .or. &
(a >= 'A' .and. a <= 'F') .or. &
(a >= 'a' .and. a <= 'f')
is = ((a >= '0' .and. a <= '9') .or. &
(a >= 'A' .and. a <= 'F') .or. &
(a >= 'a' .and. a <= 'f'))
end function dm_ascii_is_hex_digit

pure elemental logical function dm_ascii_is_lower(a) result(is_lower)
pure elemental logical function dm_ascii_is_lower(a) result(is)
!! Returns whether character is lower-case.
character, intent(in) :: a !! Character to check.
integer :: i
integer :: ia

i = iachar(a)
is_lower = (i >= iachar('a')) .and. (i <= iachar('z'))
ia = iachar(a)
is = ((ia >= iachar('a')) .and. (ia <= iachar('z')))
end function dm_ascii_is_lower

pure elemental logical function dm_ascii_is_octal_digit(a) result(is_octal)
pure elemental logical function dm_ascii_is_octal_digit(a) result(is)
!! Returns whether character is an octal digit.
character, intent(in) :: a !! Character to check.

is_octal = (a >= '0') .and. (a <= '7')
is = ((a >= '0') .and. (a <= '7'))
end function dm_ascii_is_octal_digit

pure elemental logical function dm_ascii_is_printable(a) result(is_printable)
pure elemental logical function dm_ascii_is_printable(a) result(is)
!! Returns whether character is printable.
character, intent(in) :: a !! Character to check.
integer :: i
integer :: ia

i = iachar(a)
is_printable = (i >= iachar(' ')) .and. (i <= int(z'7E'))
ia = iachar(a)
is = ((ia >= iachar(' ')) .and. (ia <= int(z'7E')))
end function dm_ascii_is_printable

pure elemental logical function dm_ascii_is_upper(a) result(is_upper)
pure elemental logical function dm_ascii_is_upper(a) result(is)
!! Returns whether character is upper-case.
character, intent(in) :: a !! Character to check.

is_upper = (a >= 'A') .and. (a <= 'Z')
is = ((a >= 'A') .and. (a <= 'Z'))
end function dm_ascii_is_upper

pure elemental logical function dm_ascii_is_white_space(a) result(is_white)
pure elemental logical function dm_ascii_is_white_space(a) result(is)
!! Returns whether character is white space (either `SPACE`, `TAB`,
!! `LF`, `VT`, `FF`, or `CR`).
character, intent(in) :: a !! Character to check.
integer :: i
integer :: ia

i = iachar(a)
is_white = (a == ' ') .or. (i >= int(z'09') .and. i <= int(z'0D'))
ia = iachar(a)
is = ((a == ' ') .or. (ia >= int(z'09') .and. ia <= int(z'0D')))
end function dm_ascii_is_white_space

pure function dm_ascii_unescape(str) result(res)
Expand Down
Loading

0 comments on commit 3210fa6

Please sign in to comment.