module BSON::Regexp::ClassMethods

Public Instance Methods

from_bson(buffer) click to toggle source

Deserialize the regular expression from BSON.

@param [ ByteBuffer ] buffer The byte buffer.

@return [ Regexp ] The decoded regular expression.

@see bsonspec.org/#/specification

@since 2.0.0

# File lib/bson/regexp.rb, line 178
def from_bson(buffer)
  pattern = buffer.get_cstring
  options = 0
  while (option = buffer.get_byte) != NULL_BYTE
    case option
    when IGNORECASE_VALUE
      options |= ::Regexp::IGNORECASE
    when MULTILINE_VALUE, NEWLINE_VALUE
      options |= ::Regexp::MULTILINE
    when EXTENDED_VALUE
      options |= ::Regexp::EXTENDED
    end
  end
  Raw.new(pattern, options)
end