Sha256: ecfe4b010da0a78a0ff5c52b39299787059aae243ae502dc5e2967a56f9429e2

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

/*
# Copyright 2022 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
*/

/*
# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
*/

#include "ruby.h"
#include "stdio.h"

/*
 * Removes quotes from the given string if present.
 *
 *   "'quoted string'".remove_quotes #=> "quoted string"
 */
static VALUE string_remove_quotes(VALUE self)
{
  long length = RSTRING_LEN(self);
  char *ptr = RSTRING_PTR(self);
  char first_char = 0;
  char last_char = 0;

  if (length < 2)
  {
    return self;
  }

  first_char = ptr[0];
  if ((first_char != 34) && (first_char != 39))
  {
    return self;
  }

  last_char = ptr[length - 1];
  if (last_char != first_char)
  {
    return self;
  }

  return rb_str_new(ptr + 1, length - 2);
}

/*
 * Initialize methods for String Core Ext
 */
void Init_string(void)
{
  rb_define_method(rb_cString, "remove_quotes", string_remove_quotes, 0);
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
openc3-5.0.11 ext/openc3/ext/string/string.c
openc3-5.0.10 ext/openc3/ext/string/string.c
openc3-5.0.9 ext/openc3/ext/string/string.c
openc3-5.0.8 ext/openc3/ext/string/string.c
openc3-5.0.7 ext/openc3/ext/string/string.c
openc3-5.0.6 ext/openc3/ext/string/string.c