Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ziglang/zig
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 339d48ac1558
Choose a base ref
...
head repository: ziglang/zig
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: afbbdb2c6712
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Nov 21, 2017

  1. rework std.base64 api

    * rename decode to decodeExactUnsafe.
    * add decodeExact, which checks for invalid chars and padding.
    * add decodeWithIgnore, which also allows ignoring chars.
    * alphabets are supplied to the decoders with their
      char-to-index mapping already built, which enables it to be
      done at comptime.
    * all decode/encode apis except decodeWithIgnore require dest
      to be the exactly correct length. This is calculated by a
      calc function corresponding to each api. These apis no longer
      return the dest parameter.
    * for decodeWithIgnore, an exact size cannot be known a priori.
      Instead, a calc function gives an upperbound, and a runtime
      error is returned in case of overflow. decodeWithIgnore
      returns the number of bytes written to dest.
    
    closes #611
    thejoshwolfe committed Nov 21, 2017
    Copy the full SHA
    a44283b View commit details
  2. Copy the full SHA
    afbbdb2 View commit details
Showing with 451 additions and 143 deletions.
  1. +8 −4 doc/langref.html.in
  2. +4 −1 example/mix_o_files/base64.zig
  3. +432 −133 std/base64.zig
  4. +7 −5 std/os/index.zig
12 changes: 8 additions & 4 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
@@ -5412,10 +5412,14 @@ const c = @cImport({
export fn decode_base_64(dest_ptr: &u8, dest_len: usize,
source_ptr: &const u8, source_len: usize) -> usize
{
const src = source_ptr[0...source_len];
const dest = dest_ptr[0...dest_len];
return base64.decode(dest, src).len;
}</code></pre>
const src = source_ptr[0..source_len];
const dest = dest_ptr[0..dest_len];
const base64_decoder = base64.standard_decoder_unsafe;
const decoded_size = base64_decoder.calcSize(src);
base64_decoder.decode(dest[0..decoded_size], src);
return decoded_size;
}
</code></pre>
<h4>test.c</h4>
<pre><code class="c">// This header is generated by zig from base64.zig
#include "base64.h"
5 changes: 4 additions & 1 deletion example/mix_o_files/base64.zig
Original file line number Diff line number Diff line change
@@ -3,5 +3,8 @@ const base64 = @import("std").base64;
export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) -> usize {
const src = source_ptr[0..source_len];
const dest = dest_ptr[0..dest_len];
return base64.decode(dest, src).len;
const base64_decoder = base64.standard_decoder_unsafe;
const decoded_size = base64_decoder.calcSize(src);
base64_decoder.decode(dest[0..decoded_size], src);
return decoded_size;
}
Loading