{"id":4690,"date":"2020-06-17T14:18:36","date_gmt":"2020-06-17T13:18:36","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?p=4690"},"modified":"2020-08-28T09:23:26","modified_gmt":"2020-08-28T08:23:26","slug":"utf8-iso8859-umlaute","status":"publish","type":"post","link":"http:\/\/roboblog.fatal-fury.de\/?p=4690","title":{"rendered":"Fortran: Unicode UTF8 ISO8859 Umlaute"},"content":{"rendered":"<p>Fortran Spass mit unterschiedlichen Encodings f\u00fcr Umlaute in UTF8 und ISO8859<\/p>\n<p>Kompletter Quellcode <a href=\"http:\/\/roboblog.fatal-fury.de\/wp-content\/uploads\/2020\/06\/characterClassification.F90.zip\"rel=\"\">characterClassification.F90.zip<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nfunction isUTF8umlaut(ch1, ch2)\r\n      implicit none\r\n      character, intent(in) :: ch1, ch2\r\n      integer :: code1, code2\r\n      logical :: isUTF8umlaut\r\n      \r\n      isUTF8umlaut = .false.\r\n      code1 = iachar(ch1)\r\n      code2 = iachar(ch2)\r\n      \r\n      ! UTF8 prefix ist 0xc3\r\n      if(code1 == Z'c3') then\r\n        ! \u00e4 0xa4\r\n        if(code2 == Z'a4') then\r\n          isUTF8umlaut = .true.\r\n        ! \u00fc 0xbc\r\n        else if(code2 == Z'BC') then\r\n          isUTF8umlaut = .true.\r\n        ! \u00f6 0xb6\r\n        else if(code2 == Z'B6') then\r\n          isUTF8umlaut = .true.\r\n        ! \u00c4 0x84\r\n        else if(code2 == Z'84') then\r\n          isUTF8umlaut = .true.  \r\n        ! \u00dc 0x9c\r\n        else if(code2 == Z'9C') then\r\n          isUTF8umlaut = .true.  \r\n        ! \u00d6 0x96\r\n        else if(code2 == Z'96') then\r\n          isUTF8umlaut = .true.\r\n        ! \u00df 0x9f\r\n        else if(code2 == Z'9f') then\r\n          isUTF8umlaut = .true.\r\n        ! ? 0xE1 0xBA 0x9E\r\n!         else if(code2 == Z'') then\r\n!           write(*,*) &quot;UTF8 ?&quot;\r\n!           isUTF8umlaut = .true.  \r\n        endif\r\n      endif\r\n    end function\r\n    \r\n    function isISO8859_15_Umlaut(ch)\r\n      implicit none\r\n      character, intent(in) :: ch\r\n      integer :: code\r\n      logical :: isISO8859_15_Umlaut\r\n      \r\n      isISO8859_15_Umlaut = .false.\r\n      code = iachar(ch)\r\n      \r\n      ! \u00e4\r\n      if(code == Z'E4') then\r\n        isISO8859_15_Umlaut = .true.\r\n      ! \u00fc\r\n      else if(code == Z'FC') then\r\n        isISO8859_15_Umlaut = .true.\r\n      ! \u00f6\r\n      else if(code == Z'F6') then\r\n        isISO8859_15_Umlaut = .true.\r\n      ! \u00c4\r\n      else if(code == Z'C4') then\r\n        isISO8859_15_Umlaut = .true.\r\n      ! \u00dc\r\n      else if(code == Z'DC') then\r\n        isISO8859_15_Umlaut = .true.\r\n      ! \u00d6\r\n      else if(code == Z'D6') then\r\n        isISO8859_15_Umlaut = .true.\r\n      ! \u00df\r\n      else if(code == Z'DF') then\r\n        isISO8859_15_Umlaut = .true.\r\n      endif        \r\n    end function\r\n<\/pre>\n<p>Um das Encoding eines Strings herauszufinden, einfach \u00fcber jedes Zeichen iterieren<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n  subroutine checkEncoding(string)\r\n    implicit none\r\n    character(len=*), intent(in) :: string\r\n\r\n    integer :: j\r\n    logical :: skipNext, detectISO8850, detectUTF8\r\n    character :: ch1, ch2\r\n\r\n    skipNext = .false.\r\n    detectUTF8 = .false.\r\n    detectISO8850 = .false.\r\n\r\n    do j=1, len(string)-1\r\n      if(skipNext) then\r\n        skipNext = .false.\r\n      else\r\n        ch1 = string(j:j)\r\n        ch2 = string(j+1:j+1)\r\n\r\n        if(isUTF8umlaut(ch1, ch2)) then\r\n          detectUTF8 = .true.\r\n          skipNext = .true.\r\n        else if(isISO8859_15_Umlaut(ch1)) then\r\n          detectISO8850 = .true.\r\n        else if(isPrint(ch1)) then\r\n\r\n        else\r\n          write(*,*) &quot;Unknown encoding im Feld 'Kommentar', Spalte&quot;, j, &quot; Zeichen '&quot;, ch1, &quot;' ASCII code &quot;, iachar(ch1)\r\n        endif\r\n      endif\r\n    end do\r\n\r\n    if(detectUTF8) then\r\n        write(*,*) &quot;UTF8 encoding detected&quot;\r\n    endif\r\n\r\n    if(detectISO8850) then\r\n      write(*,*) &quot;ISO8850 encoding detected&quot;\r\n    endif\r\n\r\n    if(detectUTF8 .and. detectISO8850) then\r\n      write(*,*) &quot;Mixed encoding detected.&quot;\r\n    endif\r\n  end subroutine\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Fortran Spass mit unterschiedlichen Encodings f\u00fcr Umlaute in UTF8 und ISO8859 Kompletter Quellcode characterClassification.F90.zip function isUTF8umlaut(ch1, ch2) implicit none character, intent(in) :: ch1, ch2 integer :: code1, code2 logical :: isUTF8umlaut isUTF8umlaut = .false. code1 = iachar(ch1) code2 = iachar(ch2) ! UTF8 prefix ist 0xc3 if(code1 == Z'c3') then ! \u00e4 0xa4 if(code2 == Z'a4') [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[30],"class_list":["post-4690","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-fortran"],"_links":{"self":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/4690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4690"}],"version-history":[{"count":6,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/4690\/revisions"}],"predecessor-version":[{"id":4738,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/4690\/revisions\/4738"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4690"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}