Skip to content

Instantly share code, notes, and snippets.

View patrickt's full-sized avatar
🍉

Patrick Thomson patrickt

🍉
View GitHub Profile
/*
* MacRuby implementation of transcode.c.
*
* This file is covered by the Ruby license. See COPYING for more details.
*
* Copyright (C) 2007-2010, Apple Inc. All rights reserved.
* Copyright (C) 1993-2007 Yukihiro Matsumoto
* Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
* Copyright (C) 2000 Information-technology Promotion Agency, Japan
*/
Index: encoding.c
===================================================================
--- encoding.c (revision 4140)
+++ encoding.c (working copy)
@@ -146,6 +146,32 @@ mr_enc_dummy_p(VALUE self, SEL sel)
return Qfalse;
}
+// For UTF-[8, 16, 32] it's /uFFFD, and for others it's '?'
+rb_str_t *replacement_string_for_encoding(rb_encoding_t* destination)
%%{
machine irc_rooms;
html_colors := '#' xdigit{6};
named_escapes := '#' lower{2,} ';'
numeric_escapes := '#&' digit{2,4} ';
html_escapes := named_entities | numeric_escapes
diff --git a/encoding.c b/encoding.c
index 3c5a65b..0b17fe3 100644
--- a/encoding.c
+++ b/encoding.c
@@ -18,7 +18,7 @@
VALUE rb_cEncoding;
rb_encoding_t *default_internal = NULL;
-static rb_encoding_t *default_external = NULL;
+rb_encoding_t *default_external = NULL;
/*
* MacRuby implementation of Ruby 1.9's io.c.
*
* This file is covered by the Ruby license. See COPYING for more details.
*
* Copyright (C) 2007-2010, Apple Inc. All rights reserved.
* Copyright (C) 1993-2007 Yukihiro Matsumoto
* Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
* Copyright (C) 2000 Information-technology Promotion Agency, Japan
*/
class Object
def metaclass
class << self
self
end
end
end
a = 'macruby'
diff --git a/encoding.c b/encoding.c
index af07b99..bb75351 100644
--- a/encoding.c
+++ b/encoding.c
@@ -146,6 +146,32 @@ mr_enc_dummy_p(VALUE self, SEL sel)
return Qfalse;
}
+// For UTF-[8, 16, 32] it's /uFFFD, and for others it's '?'
+rb_str_t *replacement_string_for_encoding(rb_encoding_t* destination)
/*
* MacRuby implementation of transcode.c.
*
* This file is covered by the Ruby license. See COPYING for more details.
*
* Copyright (C) 2007-2010, Apple Inc. All rights reserved.
* Copyright (C) 1993-2007 Yukihiro Matsumoto
* Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
* Copyright (C) 2000 Information-technology Promotion Agency, Japan
*/
/*
An implementation of the Kahan summation algorithm:
http://en.wikipedia.org/wiki/Kahan_summation_algorithm
Tested on Clang 1.5.
Released into the public domain by Patrick Thomson.
*/
#include <stdio.h>
#include <stddef.h>

An Unordered and Incomplete List of Things You Should Probably Never Use/Do in Ruby

(thanks to Zach Drayer and Ben Stiglitz for their feedback)

  1. Don't use the implicit $_ style parameters where any reasonably sane person might expect a parameter, like #puts.
  2. Don't use the string-manipulation methods included in Kernel, like chomp, chop, sub, and gsub. Call them on String instances instead. If you use these methods in combination with $_ style parameters, you are why we can't have nice things.
  3. Don't use callcc, because it's inefficient, leaks like a sieve, and isn't included in most implementations.
  4. Don't call Array#pack or String#unpack to store data. YAML/Marshal are more powerful and miles saner.
  5. Don't use Kernel#test. Come on, this isn't Perl. Compare the fields of File.stat instead.
  6. Don't use Kernel#syscall or IO#syscall. You shouldn't even do this in C.