def to_class_case(s): if not su.is_string(s): return s if not su.is_full_string(s): return s if su.is_camel_case(s): return s[0].upper() + s[1:] sub = re.sub('^[0-9_]+', '', to_snake_case(s)) camel = su.snake_case_to_camel(sub) return camel[0].upper() + camel[1:]
def to_class_case(s): if not su.is_string(s): logger.debug('{s} is not a string'.format(s=s)) return s if not su.is_full_string(s): logger.debug('string is blank'.format(s=s)) return s if su.is_camel_case(s): logger.debug('string is already camel case'.format(s=s)) return s[0].upper()+s[1:] sub = re.sub('^[0-9_]+', '', to_snake_case(s)) logger.debug('sub = {sub}'.format(sub=sub)) camel = su.snake_case_to_camel(sub) return camel[0].upper()+camel[1:]
def to_plural(s): if not su.is_string(s): return s if not su.is_full_string(s): return s if s[-1:] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']: return s if s[-1:] == 'f': return s[:-1] + 'ves' if s[-2:] == 'us': return s[:-2] + 'i' if s[-2:] == 'ay': return s + 's' if s[-1:] in ['y', 'i']: return s[:-1] + 'ies' if s[-1:] == 's': return s + 'es' return s + 's'
def to_title_case(s): if not su.is_string(s): return s if not su.is_full_string(s): return s return to_snake_case(s, separator=' ').title()
def test_return_false_for_non_string_objects(self): self.assertFalse(is_string(None)) self.assertFalse(is_string(False)) self.assertFalse(is_string(0)) self.assertFalse(is_string([])) self.assertFalse(is_string({'a': 1}))
def test_return_true_for_string_objects(self): self.assertTrue(is_string('')) self.assertTrue(is_string('hello world')) self.assertTrue(is_string(r'[a-z]'))
def test_bytes_sequence_is_ont_considered_string(self): self.assertFalse(is_string(b'nope!'))