Convert to Suzhou numerals

JavaScript, 81 bytes

s=>s.replace(/./g,c=>(p=14>>c&!p)|c>3?eval(`"\\u302${c}"`):'〇一二三'[c],p=0)

Try it online!

Using 14>>c saves 3 bytes. Thanks to Arnauld.


R, 138 bytes

I'll bet there's an easier way to do this. Use gsub to get the alternating numeric positions.

function(x,r=-48+~x)Reduce(paste0,ifelse(58<~gsub("[123]{2}","0a",x),"123"["一二三",r],'0-9'["〇〡-〩",r]))
"~"=utf8ToInt
"["=chartr

Try it online!


Retina, 46 bytes

/[1-3]{2}|./_T`d`〇〡-〩`^.
T`123`一二三

Try it online! Link includes test cases. Explanation:

/[1-3]{2}|./

Match either two digits 1-3 or any other digit.

_T`d`〇〡-〩`^.

Replace the first character of each match with its Suzhou.

T`123`一二三

Replace any remaining digits with horizontal Suzhou.

51 bytes in Retina 0.8.2:

M!`[1-3]{2}|.
mT`d`〇〡-〩`^.
T`¶123`_一二三

Try it online! Link includes test cases. Explanation:

M!`[1-3]{2}|.

Split the input into individual digits or pairs of digits if they are both 1-3.

mT`d`〇〡-〩`^.

Replace the first character of each line with its Suzhou.

T`¶123`_一二三

Join the lines back together and replace any remaining digits with horizontal Suzhou.