Module: TRuby::StringUtils
- Defined in:
- lib/t_ruby/string_utils.rb
Overview
문자열 파싱을 위한 공통 유틸리티 모듈파서와 컴파일러에서 공유하는 중첩 괄호 처리 로직
Class Method Summary collapse
-
.extract_default_value(type_and_default) ⇒ String?
기본값만 추출 (타입은 버림).
-
.split_by_comma(content) ⇒ Array<String>
중첩된 괄호를 고려하여 콤마로 문자열 분리.
-
.split_type_and_default(type_and_default) ⇒ Array
타입과 기본값 분리: “String = 0” -> [“String”, “0”] 중첩된 괄호 내부의 = 는 무시.
Class Method Details
.extract_default_value(type_and_default) ⇒ String?
기본값만 추출 (타입은 버림)
75 76 77 78 |
# File 'lib/t_ruby/string_utils.rb', line 75 def extract_default_value(type_and_default) _, default_value = split_type_and_default(type_and_default) default_value end |
.split_by_comma(content) ⇒ Array<String>
중첩된 괄호를 고려하여 콤마로 문자열 분리
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/t_ruby/string_utils.rb', line 12 def split_by_comma(content) result = [] current = "" depth = 0 content.each_char do |char| case char when "<", "[", "(", "{" depth += 1 current += char when ">", "]", ")", "}" depth -= 1 current += char when "," if depth.zero? result << current.strip current = "" else current += char end else current += char end end result << current.strip unless current.empty? result end |
.split_type_and_default(type_and_default) ⇒ Array
타입과 기본값 분리: “String = 0” -> [“String”, “0”] 중첩된 괄호 내부의 = 는 무시
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/t_ruby/string_utils.rb', line 45 def split_type_and_default(type_and_default) depth = 0 equals_pos = nil type_and_default.each_char.with_index do |char, i| case char when "<", "[", "(", "{" depth += 1 when ">", "]", ")", "}" depth -= 1 when "=" if depth.zero? equals_pos = i break end end end if equals_pos type_str = type_and_default[0...equals_pos].strip default_value = type_and_default[(equals_pos + 1)..].strip [type_str, default_value] else [type_and_default, nil] end end |