Sha256: e1563bceb86a0cb594b3cdfaae916c59853cfb6881bdc96a86560112609759ef

Contents?: true

Size: 1.04 KB

Versions: 64

Compression:

Stored size: 1.04 KB

Contents

/*
# Copyright 2014 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 General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
*/

#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

64 entries across 64 versions & 1 rubygems

Version Path
cosmos-4.5.2-java ext/cosmos/ext/string/string.c
cosmos-4.5.2 ext/cosmos/ext/string/string.c
cosmos-4.5.1-java ext/cosmos/ext/string/string.c
cosmos-4.5.1 ext/cosmos/ext/string/string.c
cosmos-4.5.0-java ext/cosmos/ext/string/string.c
cosmos-4.5.0 ext/cosmos/ext/string/string.c
cosmos-4.4.2-java ext/cosmos/ext/string/string.c
cosmos-4.4.2 ext/cosmos/ext/string/string.c
cosmos-4.4.1-java ext/cosmos/ext/string/string.c
cosmos-4.4.1 ext/cosmos/ext/string/string.c
cosmos-4.4.0-java ext/cosmos/ext/string/string.c
cosmos-4.4.0 ext/cosmos/ext/string/string.c
cosmos-4.3.0-java ext/cosmos/ext/string/string.c
cosmos-4.3.0 ext/cosmos/ext/string/string.c
cosmos-4.2.4-java ext/cosmos/ext/string/string.c
cosmos-4.2.4 ext/cosmos/ext/string/string.c
cosmos-4.2.3-java ext/cosmos/ext/string/string.c
cosmos-4.2.3 ext/cosmos/ext/string/string.c
cosmos-4.2.2-java ext/cosmos/ext/string/string.c
cosmos-4.2.2 ext/cosmos/ext/string/string.c