string to char[4] FourCC conversion

kdevel kdevel at vogtner.de
Sat May 27 13:29:06 UTC 2023


On Friday, 26 May 2023 at 13:18:15 UTC, Steven Schveighoffer 
wrote:
> [...]
> This worked for me:
>
> ```d
> char[4] fourC(string s)
> {
>     if(s.length >= 4)
>         return s[0 .. 4];

Silent truncation? Non-ASCII chars?

>     char[4] res = 0;

According to [1], [2] or [3] that should read

```
     char[4] res = ' ';
```

>     res[0 .. s.length] = s;
>     return res;
> }
> ```

[1] Multimedia Programming Interface and Data Specifications 1.0
     IBM Corporation and Microsoft Corporation
     August 1991, p. 11
     
https://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf

[2] http://ffmpeg.org/doxygen/trunk/raw_8c_source.html#l00050

[3] https://en.wikipedia.org/wiki/FourCC
"The byte sequence is usually restricted to ASCII printable 
characters, with space characters reserved for padding shorter 
sequences. [...] Some FourCCs however, do contain non-printable 
characters, and are not human-readable without special formatting 
for display; for example, 10bit Y'CbCr 4:2:2 video can have a 
FourCC of ('Y', '3', 10, 10) which ffmpeg displays as rawvideo 
(Y3[10] [10] / 0x0A0A3359), yuv422p10le."



More information about the Digitalmars-d-learn mailing list