Skip to content

Instantly share code, notes, and snippets.

@meijeru
meijeru / form.reds
Created May 3, 2011 08:20
FORM function in Red/System (improved version)
Red/System [
Title: "Form"
Purpose: {formats an integer in a c-string, as signed decimal or as hex}
Author: "Rudolf W. MEIJER"
File: %form-number.reds
Version: 0.7
Date: 27-May-2011
Notes: {Improved version, not final}
]
@meijeru
meijeru / %stringf.reds
Created May 7, 2011 17:44
String manipulation functions in Red/System, first working version
Red/System [
Title: "String functions"
Purpose: {proposed library functions for c-string manipulation}
Author: "Rudolf W. MEIJER"
File: %stringf.reds
Version: 0.1.0
Date: 27-May-2011
]
#import [
@meijeru
meijeru / reds-lex-grammar.r
Created June 25, 2011 10:18
Reds lexical grammar (is called by Reds lexer)
REBOL [
Title: "Grammar for Red/System lexical analysis"
Date: 1-Jul-2011
Name: "reds-lex-grammar"
Version: 1.0.0
File: %/G/Projects/Common/RED/red-system/sources/reds-lexer/reds-lex-grammar.r
Home: http://users.telenet.be/rwmeijer
Author: "Rudolf W. Meijer"
@meijeru
meijeru / reds-lexer.r
Created June 25, 2011 10:21
Reds lexer (drives separator + grammar)
REBOL [
Title: "Red/System lexical analysis"
Date: 1-Jul-2011
Name: "Reds lexer"
Type: none
Version: 1.0.0
File: %/G/Projects/Common/RED/red-system/sources/reds-lexer/reds-lexer.r
Home: http://users.telenet.be/rwmeijer
@meijeru
meijeru / unicode.r
Created October 25, 2011 12:25
Encoding/decoding between Unicode codepoints and UTF-8 binary strings
REBOL []
utf8-to-codepoint: func [ ; yields an integer >= 0 and < 1114112, or none
u [binary!] ; should have length 1 to 4
/local b1 b2 b3 b4
][
switch/default length? u [
1 [
b1: u/1
either b1 < 128 [
@meijeru
meijeru / unicode.reds
Created October 25, 2011 15:25
Encoding/decoding between Unicode and UTF-8: Red/System version
Red/System []
utf8-to-codepoint: func [ ; yields an integer >= 0 and < 1114112, or -1
u [c-string!] ; should have length 1 to 4
/local b1 b2 b3 b4
][
either 1 = length? u
[
b1: as-integer u/1
either b1 < 128 [
@meijeru
meijeru / unicode-multiple.r
Created October 25, 2011 17:02
UTF-8 string to block of Unicode codepoints conversion: REBOL
REBOL []
utf8-to-cps: func [ ; yields a block of integers >= 0 and < 1114112
; coding errors are skipped
u [binary!]
/local bcp b1 b2 b3 b4
][
bcp: make block! length? u ; overestimated
while [not tail? u][
b1: u/1
@meijeru
meijeru / unicode-multiple.reds
Created October 30, 2011 12:08
UTF-8 string to block of Unicode codepoints conversion: Red/System
Red/System []
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; function utf8-to-cps (cps = codepoints)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This function decodes UTF-8 information supplied as bytes in argument u
; and uses the argument res to store the array of codepoints
; (integers >= 0 and < 10FFFFh); the space for this array should have been
; allocated by the caller; an upper limit for the size of the array in bytes
@meijeru
meijeru / split.red
Last active September 28, 2015 14:48
Red mezzanine function to split a string
Red [
Title: "Split mezzanine"
Purpose: {split a string}
Author: "Rudolf W. MEIJER"
File: %split.red
Version: "0.0.0"
Date: "10-May-2015"
Rights: "(c) Copyright 2015 Rudolf W. MEIJER"
License: "TBD" ; source license (URL or full text)
]
Red [
Title: "Tile game"
Purpose: {An implementation in Red of the 4x4 sliding tile puzzle}
Author: "Rudolf W. MEIJER (meijeru)"
File: %tile-game.red
Needs: 'View
Usage: {
Click on any tile that is adjacent to the empty space
and it will shift to that space.
Try to obtain a given configuration, e.g. 1 to 15 in order.