Bob/headers/helperFunctions/HelperFunctions.h
Bobby Lucero eacb86ec77 feat: comprehensive language enhancements and code quality improvements
Major additions and improvements across the Bob language ecosystem:

Core Language Features:

- Add comprehensive dictionary support with full CRUD operations

- Implement built-in functions: keys(), values(), has() for dictionaries

- Add string multiplication operator (string * number)

- Enhance error reporting with detailed context and call stacks

- Add ternary operator support (condition ? true_expr : false_expr)

- Implement do-while loops with break/continue support

- Add array increment/decrement operators (++, --)

- Add cross-type comparison operators with proper type coercion

- Implement toInt() function for float-to-integer conversion

- Add float array index auto-truncation (like JavaScript/Lua)

Code Quality & Linter Fixes:

- Remove all "using namespace std;" statements (best practice)

- Add proper std:: prefixes throughout codebase

- Fix const correctness in helper functions

- Resolve class/struct declaration mismatches

- Fix sign comparison warnings in array indexing

- Remove unused lambda captures in built-in functions

- Fix brace initialization warnings in parser

Documentation & Tooling:

- Significantly expand BOB_LANGUAGE_REFERENCE.md with new features

- Update VS Code extension with enhanced syntax highlighting

- Add comprehensive code snippets for new language features

- Update version information and package metadata

Test Suite:

- Add extensive dictionary functionality tests

- Add tests for new operators and built-in functions

- Add comprehensive copy behavior tests (by value vs by reference)

- Add performance and edge case testing

Architecture Improvements:

- Enhance Value system with proper move semantics

- Improve memory management with shared_ptr for complex types

- Add trampoline-based tail call optimization

- Implement proper error context propagation

This represents a major milestone in Bob language development with production-ready dictionary support, comprehensive testing, and significantly improved code quality.
2025-08-07 00:12:04 -04:00

67 lines
1.9 KiB
C++

#pragma once
#include <iostream>
#include <vector>
#include <bitset>
inline std::vector<std::string> splitString(const std::string& input, const std::string& delimiter) {
std::vector<std::string> tokens;
std::string token;
size_t start = 0;
size_t end = input.find(delimiter);
while (end != std::string::npos) {
token = input.substr(start, end - start);
tokens.push_back(token);
start = end + 1;
end = input.find(delimiter, start);
}
// Add the last token (after the last delimiter)
token = input.substr(start, end);
tokens.push_back(token);
return tokens;
}
inline std::string trim(const std::string& str) {
// Find the first non-whitespace character
size_t start = str.find_first_not_of(" \t\n\r");
// If the string is all whitespace, return an empty string
if (start == std::string::npos) {
return "";
}
// Find the last non-whitespace character
size_t end = str.find_last_not_of(" \t\n\r");
// Extract the trimmed substring
return str.substr(start, end - start + 1);
}
inline std::string replaceSubstring(const std::string& str, const std::string& findSubstring, const std::string& replacement) {
std::string result = str;
size_t startPos = result.find(findSubstring);
while (startPos != std::string::npos) {
result.replace(startPos, findSubstring.length(), replacement);
startPos = result.find(findSubstring, startPos + replacement.length());
}
return result;
}
inline bool isHexDigit(char c) {
return (std::isdigit(c) || (std::isxdigit(c) && std::islower(c)));
}
inline u_long binaryStringToLong(const std::string& binaryString) {
std::string binaryDigits = binaryString.substr(2); // Remove the '0b' prefix
u_long result = 0;
for (char ch : binaryDigits) {
result <<= 1;
result += (ch - '0');
}
return result;
}