POV-Ray : Newsgroups : povray.text.scene-files : Character number lookup dict - chr.inc : Character number lookup dict - chr.inc Server Time
24 Apr 2024 21:01:32 EDT (-0400)
  Character number lookup dict - chr.inc  
From: ingo
Date: 6 Jun 2023 05:45:00
Message: <web.647eff05744ea817bac71e8ffb8ce3@news.povray.org>
A scene file I just added to my tool box directory.

As the #switch #case only compares floats and not strings I always have to
figure out what character is what number. To scratch that itch a little scene
that writes an include file for the 'reverse look up' of the chr function using
a dictionary. It covers the ascii chars 34 to 127 as I don't know how to use a
'bell' as key.


---%<------%<------%<---

// Persistence of Vision Ray Tracer Scene / Include File
// File: chars.pov
// Vers: 3.8
//
// Desc: A scenefile to create an include file with a dictionary to look up
// the ascii numbers for characters.
// Author: Ingo Janssen
// Date: 2023-06-06

#version 3.8;

global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}

#fopen CHR "chr.inc" write
#write (CHR "#version 3.8;\n
#ifndef(chr_Inc_Temp)
  #declare chr_Inc_Temp = version;
  #ifdef(View_POV_Include_Stack)
    #debug \"including chr.inc\"
  #end\n\n"
)
#write (CHR "#declare Chr = dictionary {\n")
#for (i, 34, 127)
  #if (chr(i) = "\"" | chr(i) = "\\")
  #write (CHR concat("[\"\\", chr(i),"\"] : ", str(i,0,0),"\n"))
  #else
    #write (CHR concat("[\"", chr(i),"\"] : ", str(i,0,0),"\n"))
  #end
#end
#write (CHR "};\n\n")
#write (CHR " #version chr_Inc_Temp;
#end")
#fclose CHR

#include "chr.inc"
#debug concat(str(Chr["\""], 0, 0), "\n")  // The " has to be escaped
#debug concat(str(Chr["\\"], 0, 0), "\n")  // the \ has to be escaped
#debug concat(str(Chr["F"], 0, 0), "\n")
#debug concat(str(Chr["&"], 0, 0), "\n")


---%<------%<------%<---


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.