class MemoryIO::Types::Clang::CStr

A null-terminated string.

Public Class Methods

read(stream) click to toggle source

@api private

@return [String]

String without null byte.
# File lib/memory_io/types/clang/c_str.rb, line 19
def self.read(stream)
  ret = +''
  loop do
    c = stream.read(1)
    break if c.nil? || c == '' || c == "\x00"

    ret << c
  end
  ret
end
write(stream, val) click to toggle source

@api private

@param [String] val

A null byte would be appended if +val+ not ends with null byte.
# File lib/memory_io/types/clang/c_str.rb, line 34
def self.write(stream, val)
  val = val.to_s
  val += "\x00" unless val.end_with?("\x00")
  stream.write(val)
end