String::CamelCase - camelcase, de-camelcase


String-CamelCase documentation Contained in the String-CamelCase distribution.

Index


Code Index:

NAME

Top

String::CamelCase - camelcase, de-camelcase

VERSION

Top

Version 0.01

SYNOPSIS

Top

 use String::CamelCase qw(camelize decamelize wordsplit);
 print camelize("some_keyword");  # ==> SomeKeyword
 print decamelize("SomeKeyword"); # ==> some_keyword
 print wordsplit("some_keyword"); # ==> (some, keyword)
 print wordsplit("SomeKeyword");  # ==> (Some, Keyword)

EXPORT

Top

This module can export two functions, camelize and decamelize.

FUNCTIONS

Top

camelize($under_score)

convert from under_score text to CamelCase one.

decamelize($CamelCase)

convert from CamelCase text to under_score one.

wordsplit($str)

AUTHOR

Top

YAMASHINA Hio, <hio at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-string-camelcase at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=String-CamelCase. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc String::CamelCase

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/String-CamelCase

* CPAN Ratings

http://cpanratings.perl.org/d/String-CamelCase

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=String-CamelCase

* Search CPAN

http://search.cpan.org/dist/String-CamelCase

SEE ALSO

Top

CamelCase(en.wikipedia.org) http://en.wikipedia.org/wiki/CamelCase

CamelCase(ja.wikipedia.org) http://ja.wikipedia.org/wiki/%E3%82%AD%E3%83%A3%E3%83%A1%E3%83%AB%E3%82%B1%E3%83%BC%E3%82%B9

COPYRIGHT & LICENSE

Top


String-CamelCase documentation Contained in the String-CamelCase distribution.

## ----------------------------------------------------------------------------
# String::CamelCase
# -----------------------------------------------------------------------------
# Mastering programmed by YAMASHINA Hio
#
# Copyright 2006 YAMASHINA Hio
# -----------------------------------------------------------------------------
# $Id$
# -----------------------------------------------------------------------------
package String::CamelCase;

use warnings;
use strict;

our $VERSION = '0.02';

use base qw(Exporter);
our @EXPORT_OK = qw(camelize decamelize wordsplit);

1;

sub wordsplit
{
	my $s = shift;
	split( /[_\s]+|\b|(?<![A-Z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/, $s );
}

sub camelize
{
	my $s = shift;
	join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s));
}

sub decamelize
{
	my $s = shift;
	$s =~ s{([^a-zA-Z]?)([A-Z]*)([A-Z])([a-z]?)}{
				my $fc = pos($s)==0;
				my ($p0,$p1,$p2,$p3) = ($1,lc$2,lc$3,$4);
				my $t = $p0 || $fc ? $p0 : '_';
				$t .= $p3 ? $p1 ? "${p1}_$p2$p3" : "$p2$p3" : "$p1$p2";
				$t;
		}ge;
	$s;
}

__END__

# -----------------------------------------------------------------------------
# End of File.
# -----------------------------------------------------------------------------