55 Commits

Author SHA1 Message Date
Campbell Barton
99ed1bd46b Cleanup: use doxygen style comments for doc-strings 2025-10-08 15:19:01 +11:00
Brecht Van Lommel
c826b0630d Color Management: Group SDR and HDR displays in menu
This helps users discover that they should use Rec.2100 PQ for HDR.

And drop redundant "- Display" suffix from ACES config, makes the menu look
more clean.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/144565
2025-08-21 15:25:09 +02:00
Campbell Barton
accacc65fc BLI_string_ref: add copy_bytes_truncated method
Needed to copy non UTF8 bytes into a null terminated string.

Ref !144052
2025-08-07 06:25:29 +10:00
Campbell Barton
b3dfde88f3 Cleanup: spelling in comments (check_spelling_* target)
Also uppercase acronyms: API, UTF & ASCII.
2025-05-17 10:17:37 +10:00
Hans Goudey
730d0dfc0c Cleanup: Fix constexpr for StringRefNull c-string constructor
Similar to c4d5145070.
2025-03-28 21:10:42 -04:00
Jacques Lucke
3263dd6333 Fix: Geometry Nodes: unescape column names after csv import 2025-02-19 12:36:19 +01:00
Brecht Van Lommel
6b6cd3307b Cleanup: Various clang-tidy warnings in blenlib
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:17 +01:00
Jacques Lucke
e1753900b7 BLI: improve UTF-8 safety when copying StringRef to char buffers
Previously, there was a `StringRef.copy` method which would copy the string into
the given buffer. However, it was not defined for the case when the buffer was
too small. It moved the responsibility of making sure the buffer is large enough
to the caller.

Unfortunately, in practice that easily hides bugs in builds without asserts
which don't come up in testing much. Now, the method is replaced with
`StringRef.copy_utf8_truncated` which has much more well defined semantics and
also makes sure that the string remains valid utf-8.

This also renames `unsafe_copy` to `copy_unsafe` to make the naming more similar
to `copy_utf8_truncated`.

Pull Request: https://projects.blender.org/blender/blender/pulls/133677
2025-01-29 12:12:27 +01:00
Sean Kim
c4d5145070 Fix: StringRefNull constructor not constexpr
`strlen` is not labeled as `constexpr` and cannot be used, this commit
switches it for `std::char_traits<char>::length` which is labeled as
such since C++17

See: https://en.cppreference.com/w/cpp/string/char_traits/length

Pull Request: https://projects.blender.org/blender/blender/pulls/131266
2024-12-03 21:37:13 +01:00
Guillermo Venegas
4a23553b83 BLI: avoid initializing StringRefNull with explicit nullptr
`StringRefNull ` expects a null terminated string and `StringRefNull (const char *)` initializer
already realizes a runtime assert to avoid `nullptr` c strings, however this stills allows
initializing `StringRefNull ` with a explicit `nullptr`.

Deleting  `StringRefNull(std::nullptr_t)` gives a error if `StringRefNull` is initialized with a implicit `nullptr`.

This follows the same deleted `std::string(std::nullptr_t)` initializer in c++23.

Pull Request: https://projects.blender.org/blender/blender/pulls/130935
2024-12-02 15:30:27 +01:00
Sybren A. Stüvel
c120ead9df BLI: Clarify and test StringRefNull comparisons
Add some comments that clarify that `StringRefNull` can be compared with
other `StringRefNull` and with `StringRef` instances.

Add unit tests that cover these cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/118515
2024-02-20 17:52:14 +01:00
Campbell Barton
9996d95ab9 Cleanup: spelling in comments 2024-02-06 22:28:10 +11:00
Jacques Lucke
442429a97c BLI: support formatting StringRef with the fmt library
People were manually converting it to `std::string_view` in many places already.
It's easy enough to allow using `StringRef` directly by providing a `format_as` function.

Also see https://fmt.dev/latest/api.html#udt.

Pull Request: https://projects.blender.org/blender/blender/pulls/117788
2024-02-03 19:14:51 +01:00
Hans Goudey
038ad97a7c BLI: Avoid computing size when referencing std::string
The std::string already knows its size; there's no need to find it from scratch.

Pull Request: https://projects.blender.org/blender/blender/pulls/117757
2024-02-02 17:48:52 +01:00
Aras Pranckevicius
acbd952abf Cleanup: fewer iostreams related includes from BLI/BKE headers
Including <iostream> or similar headers is quite expensive, since it
also pulls in things like <locale> and so on. In many BLI headers,
iostreams are only used to implement some sort of "debug print",
or an operator<< for ostream.

Change some of the commonly used places to instead include <iosfwd>,
which is the standard way of forward-declaring iostreams related
classes, and move the actual debug-print / operator<< implementations
into .cc files.

This is not done for templated classes though (it would be possible
to provide explicit operator<< instantiations somewhere in the
source file, but that would lead to hard-to-figure-out linker error
whenever someone would add a different template type). There, where
possible, I changed from full <iostream> include to only the needed
<ostream> part.

For Span<T>, I just removed print_as_lines since it's not used by
anything. It could be moved into a .cc file using a similar approach
as above if needed.

Doing full blender build changes include counts this way:
- <iostream> 1986 -> 978
- <sstream> 2880 -> 925

It does not affect the total build time much though, mostly because
towards the end of it there's just several CPU cores finishing
compiling OpenVDB related source files.

Pull Request: https://projects.blender.org/blender/blender/pulls/111046
2023-08-16 09:51:37 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Sergey Sharybin
c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Sergey Sharybin
d32d787f5f Clang-Format: Allow empty functions to be single-line
For example

```
OIIOOutputDriver::~OIIOOutputDriver()
{
}
```

becomes

```
OIIOOutputDriver::~OIIOOutputDriver() {}
```

Saves quite some vertical space, which is especially handy for
constructors.

Pull Request: https://projects.blender.org/blender/blender/pulls/105594
2023-03-29 16:50:54 +02:00
Jacques Lucke
5d07b0e6da Cleanup: delegate to string_view equality for StringRef
This also fixes an issue introduced in rBd3e8d63a8c455d0,
where the function relied on the `StringRef` being null-terminated.
2023-01-11 13:19:11 +01:00
Campbell Barton
d3e8d63a8c Fix error in StringRef equality
Regression in [0] wasn't correct as it's important for empty strings
to be equal to nullptr.

[0]: 9f283bee7e
2023-01-11 20:04:00 +11:00
Campbell Barton
9f283bee7e BLI_string_ref: avoid passing null to strncmp (quiet ASAN warning)
The existing logic to avoid passing null only worked when both
strings were null.
2023-01-11 13:04:23 +11:00
Campbell Barton
333e41eac6 Cleanup: replace C-style casts with functional casts for numeric types
Use function style casts in C++ headers & source.
2022-09-26 17:58:36 +10:00
Jacques Lucke
c6e70e7bac Cleanup: follow C++ type cast style guide in some files
https://wiki.blender.org/wiki/Style_Guide/C_Cpp#C.2B.2B_Type_Cast

This was discussed in https://devtalk.blender.org/t/rfc-style-guide-for-type-casts-in-c-code/25907.
2022-09-25 17:39:45 +02:00
Campbell Barton
c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Campbell Barton
7e6066c9c3 Cleanup: clang-format 2022-02-07 15:32:34 +11:00
Aras Pranckevicius
a20cfb9eff BLI: use methods specialized for finding a single char in StringRef
Previously, these methods used the more generic substring-finding
algorithm, which is more complex and slower.

Using the more specialized methods results in a noticable speedup
in the obj importer (D13958).

Differential Revision: https://developer.blender.org/D14012
2022-02-04 10:38:05 +01:00
Clément Foucault
e729abb0e2 BLI_string_ref: Add back missing rfind()
Must have been removed in a bad merge or something.
2022-01-26 18:10:59 +01:00
Campbell Barton
3d3bc74884 Cleanup: remove redundant const qualifiers for POD types
MSVC used to warn about const mismatch for arguments passed by value.
Remove these as newer versions of MSVC no longer show this warning.
2022-01-07 14:16:26 +11:00
Jacques Lucke
698b05fc58 BLI: avoid passing nullptr to strncmp
This resulted in an ASAN warning.
2021-11-02 15:07:50 +01:00
Campbell Barton
1411118055 Cleanup: spelling in comments 2021-10-24 21:04:04 +11:00
Campbell Barton
2b66b372bc Cleanup: use doxygen sections 2021-10-05 11:10:25 +11:00
Jacques Lucke
a8d6a86981 Cleanup: move StringRef method definitions out of class
This makes the classes more appealing to look at and makes
it easier to see what different methods are available.
2021-10-03 14:10:26 +02:00
Jacques Lucke
a28ec92088 BLI: avoid warning when copying empty StringRef 2021-09-22 19:45:18 +02:00
Sybren A. Stüvel
7e91a60be6 Add StringRef::trim() functions
Add three functions that trim characters from the front & end of a
`StringRef`. All functions return a new `StringRef` that references a
sub-string of the original `StringRef`.

- `trim(chars_to_remove)`: strips all characters from the start and end
  that occur in `chars_to_remove`.
- `trim(char_to_remove)`: same, but with a single character to remove.
- `trim()`: remove leading & trailing whitespace, so same as
  `trim(" \r\n\t")`

Reviewed By: JacquesLucke

Differential Revision: https://developer.blender.org/D12031
2021-07-27 19:49:29 +02:00
Jacques Lucke
6c2e1f3398 BLI: cleanup StringRef and Span and improve parameter validation
Previously, methods like `Span.drop_front` would crash when more
elements would be dropped than are available. While this is most
efficient, it is not very practical in some use cases. Also other languages
silently clamp the index, so one can easily write wrong code accidentally.

Now, `Span.drop_front` and similar methods will only crash when n
is negative. Too large values will be clamped down to their maximum
possible value. While this is slightly less efficient, I did not have a case
where this actually mattered yet. If it does matter in the future, we can
add a separate `*_unchecked` method.

This should not change the behavior of existing code.
2021-02-20 22:05:50 +01:00
Ankit Meel
d23a5b1d88 BLI: constexpr Span, IndexRange, StringRef(Null/Base)
Motivated by `std::string_view` being usable in
const (compile-time) context.
One functional change was needed for StringRef:
`std::char_traits<char>::length(str)` instead of `strlen`.

Reviewed By: JacquesLucke, LazyDodo
Differential Revision: https://developer.blender.org/D9788
2020-12-16 13:03:46 +05:30
Jacques Lucke
ddbe3274ef BLI: add missing const 2020-12-02 15:38:47 +01:00
Jacques Lucke
d71458d919 BLI: add comparison operators for StringRef
The semantic of those is the same as for std::string_view.
2020-09-07 16:10:01 +02:00
Jacques Lucke
519b2f937f BLI: add index_range method for StringRef 2020-09-03 16:26:45 +02:00
Campbell Barton
0c0f972e86 Cleanup: spelling 2020-08-11 13:19:09 +10:00
Jacques Lucke
c521b69ffb BLI: improve StringRef for C++17
Since C++17 there is also std::string_view, which is similar to StringRef.
This commit does a couple of things:
* New implicit conversions between StringRef and std::string_view.
* Support std::string_view in blender::DefaultHash.
* Support most of the methods that std::string_view has.
* Add StringRef::not_found which can be used instead of -1 in some places.
* Improve/fix the description at the top of BLI_string_ref.hh.
2020-08-10 18:17:07 +02:00
Jacques Lucke
c50e5fcc34 Cleanup: use C++ style casts in various places 2020-08-07 18:42:21 +02:00
Jacques Lucke
91694b9b58 Code Style: use "#pragma once" in source directory
This replaces header include guards with `#pragma once`.
A couple of include guards are not removed yet (e.g. `__RNA_TYPES_H__`),
because they are used in other places.

This patch has been generated by P1561 followed by `make format`.

Differential Revision: https://developer.blender.org/D8466
2020-08-07 09:50:34 +02:00
Jacques Lucke
8cbbdedaf4 Refactor: Update integer type usage
This updates the usage of integer types in code I wrote according to our new style guides.

Major changes:
* Use signed instead of unsigned integers in many places.
* C++ containers in blenlib use `int64_t` for size and indices now (instead of `uint`).
* Hash values for C++ containers are 64 bit wide now (instead of 32 bit).

I do hope that I broke no builds, but it is quite likely that some compiler reports
slightly different errors. Please let me know when there are any errors. If the fix
is small, feel free to commit it yourself.
I compiled successfully on linux with gcc and on windows.
2020-07-20 12:16:20 +02:00
Jacques Lucke
0e3d34e48f BLI: add StringRefNull.c_str() method
This should be used whenever you rely on the fact, that the
returned pointer points to the beginning of a null-terminated array.
2020-07-17 12:38:15 +02:00
Jacques Lucke
93da09d717 Cleanup: add const in various places 2020-07-03 14:53:06 +02:00
Jacques Lucke
d64803f63b Cleanup: Use trailing underscore for non-public data members
This makes the code conform better with our style guide.
2020-07-03 14:16:02 +02:00
Campbell Barton
b838a51803 Cleanup: spelling 2020-06-30 20:54:31 +10:00
Campbell Barton
dea2c3f256 Cleanup: spelling 2020-06-13 12:50:07 +10:00
Jacques Lucke
4c172f7ca6 BLI: support constructing StringRef from start and end pointer 2020-06-10 18:27:18 +02:00