convert_to_native_type (KBTypeConversionsMixin)

    # File lib/kirbybase.rb, line 198
        def convert_to_native_type(data_type, s)
            return kb_nil if s == KB_NIL

            # I added this line to keep KBTable#import_csv working after I made

            # the kb_nil changes.

            return nil if s.nil?

            case data_type
            when :String
                if s =~ UNENCODE_RE
                    return s.gsub('&linefeed;', "\n").gsub('&carriage_return;',
                     "\r").gsub('&substitute;', "\032").gsub('&pipe;', "|"
                     ).gsub('&amp;', "&")
                else
                    return s
                end
            when :Integer
                return s.to_i
            when :Float
                return s.to_f
            when :Boolean
                if ['false', 'False', nil, false].include?(s)
                    return false
                else
                    return true
                end
            when :Time
                return Time.parse(s)
            when :Date
                return Date.parse(s)
            when :DateTime
                return DateTime.parse(s)
            when :YAML
                # This code is here in case the YAML field is the last

                # field in the record.  Because YAML normally defines a

                # nil value as "--- ", but KirbyBase strips trailing

                # spaces off the end of the record, so if this is the

                # last field in the record, KirbyBase will strip the

                # trailing space off and make it "---".  When KirbyBase

                # attempts to convert this value back using to_yaml,

                # you get an exception.

                if s == "---"
                    return nil
                elsif s =~ UNENCODE_RE
                    y = s.gsub('&linefeed;', "\n").gsub('&carriage_return;',
                     "\r").gsub('&substitute;', "\032").gsub('&pipe;', "|"
                     ).gsub('&amp;', "&")
                    return YAML.load(y)
                else
                    return YAML.load(s)
                end
            when :Memo
                memo = KBMemo.new(@tbl.db, s)
                memo.read_from_file
                return memo
            when :Blob
                blob = KBBlob.new(@tbl.db, s)
                blob.read_from_file
                return blob
            else
                raise "Invalid field type: %s" % data_type
            end
        end