class BinData::Stringz

def trim_to(str, max_length = nil)

def trim_to(str, max_length = nil)
  result = str
  if max_length
    max_length = 1 if max_length < 1
    result = result[0, max_length]
    if result.length == max_length and result[-1, 1] != "\0"
      result[-1, 1] = "\0"
    end
  end
  result
end