コード例 #1
0
ファイル: calendar.c プロジェクト: noahdiewald/icu4r
VALUE icu4r_cal_cmp (VALUE c1, VALUE c2) 
{
	UErrorCode status = U_ZERO_ERROR;
	double  millis1, millis2;
	Check_Class(c1, rb_cUCalendar);
	Check_Class(c2, rb_cUCalendar);
	millis1 = ucal_getMillis(UCALENDAR(c1), &status); 
	millis2 = ucal_getMillis(UCALENDAR(c2), &status); 
	ICU_RAISE(status);
	if(millis1 < millis2) return INT2FIX(-1);
	if(millis1 > millis2) return INT2FIX(1);
	return INT2FIX(0);
}
コード例 #2
0
static VALUE rb_libarchive_reader_extract(int argc, VALUE *argv, VALUE self) {
  VALUE v_entry, v_flags;
  struct rb_libarchive_archive_container *pa;
  struct rb_libarchive_entry_container *pae;
  int flags = 0;
  rb_scan_args(argc, argv, "11", &v_entry, &v_flags);
  Check_Class(v_entry, rb_cArchiveEntry);

  if (!NIL_P(v_flags)) {
    flags = (NUM2INT(v_flags) & EXTRACT_FLAGS);
  }

  Data_Get_Struct(self, struct rb_libarchive_archive_container, pa);
  Check_Archive(pa);

  if (pa->eof) {
    rb_raise(rb_eArchiveError, "Extract archive failed: It has already reached EOF");
  }

  Data_Get_Struct(v_entry, struct rb_libarchive_entry_container, pae);
  Check_Entry(pae);

  if (archive_read_extract(pa->ar, pae->ae, flags) != ARCHIVE_OK) {
    rb_raise(rb_eArchiveError, "Extract archive failed: %s", archive_error_string(pa->ar));
  }

  return Qnil;
}
コード例 #3
0
ファイル: calendar.c プロジェクト: noahdiewald/icu4r
/**
 * call-seq:
 *     UCalendar.new(zone_id = nil, locale = nil, traditional = false)
 *
 * Creates new instance of UCalendar, for given time zone id (UString),
 * locale (Ruby String), and kind , by default gregorian.
 * New instance has current time.
 *
 */
VALUE icu4r_cal_init (int argc, VALUE * argv, VALUE self)
{
         VALUE zone, loc, cal_type;
	 UChar * zone_id = NULL;
	 char  * locale  = NULL;
	 UCalendarType  c_type = UCAL_GREGORIAN;
	 int32_t n, zone_len =0 , locale_len =0;
	 UCalendar * calendar;
	 UErrorCode  status = U_ZERO_ERROR;
	 n = rb_scan_args(argc, argv, "03", &zone, &loc, &cal_type);
	 if( n >= 1) {
	     Check_Class(zone, rb_cUString);
	     zone_id = ICU_PTR(zone);
	     zone_len = ICU_LEN(zone);
	 }
	 if( n >= 2) {
	     Check_Type(loc, T_STRING);
	     locale = RSTRING_PTR(loc);
	     locale_len = RSTRING_LEN(loc);
	 }
	 if( n >= 3) {
	     if( Qtrue == cal_type ) {
	     	c_type = UCAL_TRADITIONAL;
	     }
	 }
	 calendar = ucal_open(zone_id, zone_len, locale,  c_type, &status);
	 ICU_RAISE(status);
	 DATA_PTR(self) = calendar;
	 return self;
}
コード例 #4
0
ファイル: calendar.c プロジェクト: noahdiewald/icu4r
/** 
 * call-seq:
 *     UCalendar.default_tz = ustring
 *
 * Set the default time zone.
 *
 *      UCalendar.default_tz="GMT+00".u
 *      UCalendar.default_tz="Europe/Paris".u
 */
VALUE icu4r_cal_set_default_tz(VALUE obj, VALUE tz) 
{
	UErrorCode  status = U_ZERO_ERROR;
	Check_Class(tz, rb_cUString);
  	ucal_setDefaultTimeZone (ICU_PTR(tz), &status);	
	ICU_RAISE(status);
	return tz;
}
コード例 #5
0
ファイル: calendar.c プロジェクト: noahdiewald/icu4r
/** 
 * call-seq:
 *     calendar.time_zone = zone_id
 *
 * Set the TimeZone used by a UCalendar. 
 */
VALUE icu4r_cal_set_tz(VALUE obj, VALUE zone)
{
	UErrorCode status = U_ZERO_ERROR;
	Check_Class(zone, rb_cUString);
	ucal_setTimeZone(UCALENDAR(obj), ICU_PTR(zone), ICU_LEN(zone), &status);
	ICU_RAISE(status);
	return Qnil;

}
コード例 #6
0
ファイル: calendar.c プロジェクト: noahdiewald/icu4r
/**
 * call-seq:
 *      UCalendar.dst_savings(zone_id)
 *
 * Return the amount of time in milliseconds that the clock is advanced 
 * during daylight  savings time for the given time zone, or zero if the time 
 * zone does not observe daylight savings time. 
 *
 *       UCalendar.dst_savings("GMT+00".u) # =>  3600000
 *
 */
VALUE icu4r_cal_dst_savings(VALUE obj, VALUE zone) 
{
	UErrorCode  status = U_ZERO_ERROR;
	int32_t dst;
	Check_Class(zone, rb_cUString);
  	dst = ucal_getDSTSavings (ICU_PTR(zone), &status);
	ICU_RAISE(status);
	return INT2FIX(dst);
}
コード例 #7
0
ファイル: calendar.c プロジェクト: noahdiewald/icu4r
/** call-seq:
 *     calendar.format(pattern = nil , locale = nil)
 *
 * Formats this calendar time using given pattern and locale. Returns UString or nil on failure.
 * Valid value types for pattern are:
 *      nil        - long format for date and time
 *      UString    - specification of format, as defined in docs/FORMATTING
 *      Symbol     - one of :short, :medium, :long, :full, :none , sets format for both date and time
 *      Hash       - {:time => aSymbol, :date => aSymbol} - sets separate formats for date and time, valid symbols see above
 */
VALUE icu4r_cal_format(int argc, VALUE * argv, VALUE obj) 
{
	UErrorCode status = U_ZERO_ERROR;
	UDateFormat * format;
	UDate   time_to_format;
	UChar * buf = NULL, * pattern = NULL;
	long capa = 0, pattern_len = 0;
	char *locale = NULL;
	VALUE loc, pat, ret = Qnil;
	int n , def_d_format = UDAT_FULL, def_t_format = UDAT_FULL;
	
	n = rb_scan_args(argc, argv, "02", &pat, &loc);
	if( n == 2) {
		Check_Type(loc, T_STRING);
		locale = RSTRING_PTR(loc);
	}
	if (n >= 1 && pat != Qnil) {
		switch(TYPE(pat)) {
			case T_SYMBOL:
			 	def_d_format = def_t_format = icu4r_get_cal_format_int(pat);
				break;
			case T_HASH:
			 	def_d_format = icu4r_get_cal_format_int(rb_hash_aref(pat, ID2SYM(rb_intern("date"))));
				def_t_format = icu4r_get_cal_format_int(rb_hash_aref(pat, ID2SYM(rb_intern("time"))));
				break;
			default:
				Check_Class(pat, rb_cUString);
				pattern = ICU_PTR(pat);
				pattern_len = ICU_LEN(pat);
				break;
		}
	}
	
	format = udat_open(def_t_format, def_d_format, locale, NULL, 0,  NULL, 0, &status);
	if( pattern ) {
	   udat_applyPattern(format, 0, pattern, pattern_len);
	}
	ICU_RAISE(status);
	udat_setCalendar(format, UCALENDAR(obj));
	time_to_format = ucal_getMillis(UCALENDAR(obj), &status); 

	capa = udat_format(format, time_to_format, buf, capa, NULL, &status);
	if( U_BUFFER_OVERFLOW_ERROR == status) {
		buf = ALLOC_N(UChar, capa+1);
		status = U_ZERO_ERROR;
		capa = udat_format(format, time_to_format, buf, capa, NULL, &status);
		ret = icu_ustr_new_set(buf, capa, capa+1);
	}
	udat_close(format);
	ICU_RAISE(status);
	return ret;
}
コード例 #8
0
static VALUE rb_libarchive_writer_write_header(VALUE self, VALUE v_entry) {
  struct rb_libarchive_archive_container *pa;
  struct rb_libarchive_entry_container *pae;
  Check_Class(v_entry, rb_cArchiveEntry);
  Data_Get_Struct(self, struct rb_libarchive_archive_container, pa);
  Check_Archive(pa);
  Data_Get_Struct(v_entry, struct rb_libarchive_entry_container, pae);
  Check_Entry(pae);

  if (archive_write_header(pa->ar, pae->ae) != ARCHIVE_OK) {
    rb_raise(rb_eArchiveError, "Write header failed: %s", archive_error_string(pa->ar));
  }

  return Qnil;
}
コード例 #9
0
ファイル: collator.c プロジェクト: jchris/icu4r
/**
 * call-seq:
 *     collator.sort_key(an_ustring) -> String
 *
 * Get a sort key for a string from a UCollator. Sort keys may be compared using strcmp.
 **/
VALUE icu4r_col_sort_key(VALUE self, VALUE str)
{
    int32_t needed , capa ;
    char * buffer ; 
    VALUE ret;
    Check_Class(str, rb_cUString);
    capa = ICU_LEN(str);
    buffer = ALLOC_N(char, capa);
    needed = ucol_getSortKey(UCOLLATOR(self), ICU_PTR(str), ICU_LEN(str), buffer, capa);
    if(needed > capa){
      REALLOC_N(buffer,char, needed);
      needed = ucol_getSortKey(UCOLLATOR(self), ICU_PTR(str), ICU_LEN(str), buffer, needed);
    }
    ret = rb_str_new(buffer, needed);
    free(buffer);
    return ret;
}
コード例 #10
0
ファイル: collator.c プロジェクト: jchris/icu4r
/**
 * call-seq:
 *     collator.strcoll(ustr1, ustr2)
 *
 * Compare two UString's. The strings will be compared using the options already specified.
 **/
VALUE icu4r_col_strcoll(VALUE self, VALUE str1, VALUE str2)
{
    Check_Class(str1, rb_cUString);
    Check_Class(str2, rb_cUString);
    return INT2FIX(icu_collator_cmp(UCOLLATOR(self), str1,  str2));
}
コード例 #11
0
ファイル: abitmap.cpp プロジェクト: cstrahan/argss
VALUE ARGSS::ABitmap::rfontE(VALUE self, VALUE font) {
	ARGSS::ABitmap::CheckDisposed(self);
	Check_Class(font, ARGSS::AFont::id);
	return rb_iv_set(self, "@font", font);;
}