📄 cspace_utils.c
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */#include <ctype.h>#include "cspace_utils.h"/* c should always be a hex digit.*/int hex2dec(const char c){ /*we need not worry about lower bound since we know it is hex*/ /*keep the order intact, logic depends on the order*/ if (c <= '9') { return c - '0'; } else if (c <= 'F') { return c - 'A' + 10; } else if (c <= 'f') { return c - 'a' + 10; } return 0; /* this should never be reached.*/}void cspace_decode_url(char *url){ char *s = url, *d = url; /*source and destination pointers*/ while (*s) { if (*s == '+') { /*this should come first: we don't want to mess with the url encoded '+'s */ *d = ' '; } else if ((*s == '%') && (isxdigit(*(s + 1))) && (isxdigit(*(s + 2)))) { *d = (char)(((hex2dec(*(s + 1))) * 16) + hex2dec(*(s + 2))); s += 2; } else { *d = *s; } d ++; s ++; } *d = '\0';}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -